Question: High Tech Solutions team uses Spring JDBC for performing database operations to the User entity. The User class is designed as below public class User
High Tech Solutions team uses Spring JDBC for performing database operations to the User entity. The User class is designed as below
public class User
private Integer userId:
private String userName:
private String userUnit:
The team needs to retrieve all the user records. Assume that the jdbcTemplate is an instance of JdbcTemplate object.
Which among the following Spring JDBC template code is a valid option to fetch the records?
A
public List getUser
String sql "select userId, userName userUnit from User ;
return jdbcTemplate.query sql new RowMapper User
public User mapRow ResultSet rs int rowNum throws SQLException User user new User ;
values fetched from rs and set to the User object
return user;
;
B
public List getAll
String sql "select userId, userName
userUnit from User return jdbcTemplate.queryForObjectsql new RowMapper Usar
public User mapRow ResultSet rs int rowNum throws SQLException
User user new User ;
values fetched from rs and set to the User object return user;
;
C
public List getAll
String sql "select userId, userName userUnit from User": return jdbcTemplate.querysql User.class;
D
public List getAll
String sql "select uuserId, uuserName, uuserUnit from User u : return jdbcTemplate.executeQuery sql User.class;
public List getAll
String sql "select userId, userName userUnit from User ;
return jdbcTemplate.query sql new RowMapper
public User mapRow ResultSet rs int rowNum throws SQLException User user new User ;
values fetched from rs and set to the User object return user;
;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
