Explain with example how JdbcTemplate can be used for querying.
Answered
Explain with example how JdbcTemplate can be used for querying.
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; } }); .....