Added the code and Junit test for database queries.