Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JdbcTemplate "queryForObject" and "query" is deprecated in Spring. What should it be replaced by?

Query for object,

Student student = return jdbcTemplate.queryForObject("select * from student_id = ?", new Object[] { studentId }, studentRowMapper);

For query,

List<Student> students = return jdbcTemplate.query("select * from class_room_id = ?", new Object[] { classRoomId }, studentRowMapper);

Both jdbcTemplate.queryForObject and jdbcTemplate.query are deprecated in spring boot 2.4.X above

like image 371
Thirumal Avatar asked Dec 15 '20 06:12

Thirumal


1 Answers

As explained in the javadoc of the class as well as in the upgrade/migration guide it explains that you should use the varargs method.

jdbcTemplate.queryForObject("select * from student_id = ?", studentRowMapper, studentId);

and

List<Student> students = return jdbcTemplate.query("select * from class_room_id = ?", studentRowMapper, classRoomId);
like image 114
M. Deinum Avatar answered Sep 19 '22 16:09

M. Deinum