Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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?
16
(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.queryForObject(sql, 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.query(sql, User.class);
(D)
public List getAll(){
String sql = "select u.userId, u.userName, u.userUnit 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Jay Greenspan, Brad Bulger

1st Edition

978-0764535376

More Books

Students also viewed these Databases questions

Question

1. Discuss the four components of language.

Answered: 1 week ago

Question

a. How many different groups were represented?

Answered: 1 week ago