Explain with example how JdbcTemplate can be used for querying.

Explain with example how JdbcTemplate can be used for querying.

Ninja Asked on 19th September 2018 in Spring DAO.
Add Comment
1 Answer(s)
Best answer

The following code snippet explain how JdbcTemplate can be used for querying objects.

Employee is the name of the class which is mapped to employee table in the database.


.....

List<Employee> employees = this.jdbcTemplate.query(

"select empid, empname from employee",

new RowMapper<Employee>() {

public Employee mapRow(ResultSet rs, int rowNum) throws SQLException {

Employee emp = new Employee();

emp.setEmpId(rs.getInteger("empid"));

emp.setEmpName(rs.getString("empname"));

return emp;

}

});

.....

Ninja Answered on 19th September 2018.
Add Comment