This set of Java Spring Multiple Choice Questions & Answers (MCQs) focuses on “JDBC Template”.
1. Class which declares a number of overloaded update() template methods to control the overall update process.
a) org.springframework.jdbc.core.JdbcTemplate
b) org.springframework.jdbc.core.*
c) org.springframework.jdbc.*
d) none of the mentioned
View Answer
Explanation: The org.springframework.jdbc.core.JdbcTemplate class declares a number of overloaded update() template methods to control the overall update process.
2. You implement this interface to override the statement creation task.
a) PreparedStatement
b) PreparedStatementCreator
c) PreparedCreator
d) None of the mentioned
View Answer
Explanation: The first callback interface to introduce is PreparedStatementCreator. You implement this interface to override the statement creation task and the parameter binding task of the overall update process.
3. When implementing the PreparedStatementCreator interface, you will get the database connection as the createPreparedStatement() method’s argument.
a) True
b) False
View Answer
Explanation: All you have to do in this method is to create a PreparedStatement object on this connection and bind your parameters to this object.
4. It is better to implement the PreparedStatementCreator interface and other callback interfaces as inner classes if they are used within one method only.
a) True
b) False
View Answer
Explanation: This is because you can get access to the local variables and method arguments directly from the inner class, instead of passing them as constructor arguments.
5. PreparedStatementSetter, as its name indicates, create a PreparedStatement object on this connection the parameter as well as binding task of the overall update process.
a) True
b) False
View Answer
Explanation: The second callback interface, PreparedStatementSetter, as its name indicates, performs only the parameter binding task of the overall update process.
6. The JdbcTemplate class offers template method for batch update operations.
a) batchUpdate()
b) update()
c) all of the mentioned
d) none of the mentioned
View Answer
Explanation: It requires a SQL statement and a BatchPreparedStatementSetter object as arguments. In this method, the statement is compiled (prepared) only once and executed multiple times.
7. The JdbcTemplate class declares a number of overloaded query() template methods to control the overall query process.
a) True
b) False
View Answer
Explanation: You can override the statement creation (task 2) and the parameter binding by implementing the PreparedStatementCreator and PreparedStatementSetter interfaces, just as you did for the update operations.
8. The primary interface that allows you to process the current row of the result set.
a) PreparedStatementSetter
b) PreparedStatementCreator
c) RowCallbackHandler
d) All of the mentioned
View Answer
Explanation: RowCallbackHandler is the is the primary interface that allows you to process the current row of the result set.
9. RowCallbackHandler purpose is to map a single row of the result set to a customized object.
a) True
b) False
View Answer
Explanation: RowCallbackHandler is the is the primary interface that allows you to process the current row of the result set.
10. Method of RowMapper interface in which, you have to construct the object that represents a row and return it as the method’s return value.
a) mapRow()
b) query()
c) update()
d) none of the mentioned
View Answer
Explanation: From the viewpoint of reuse, it’s better to implement the RowMapper
11. RowMapper 12. Method which provides list of maps. 13. Spring JDBC framework offers a convenient class, to simplify your DAO implementation. 14. The org.springframework.jdbc.core.support.JdbcDaoSupport class has a setDataSource() method and a setJdbcTemplate() method. 15. Method to retrieve the JDBC template. Sanfoundry Global Education & Learning Series – Java Spring.
a) BeanPropertyRowMapper
b) BeanPropertyRow
c) All of the mentioned
d) None of the mentioned
View Answer
Explanation: Note that the specified class must be a top-level class and must have a default or no-argument constructor. It first instantiates this class and then maps each column value to a property by matching their names.
a) queryForList()
b) update
c) query()
d) all of the mentioned
View Answer
Explanation: Without the help of RowMapper
a) org.springframework.jdbc.core.support
b) org.springframework.jdbc.core.support.JdbcDaoSupport
c) all of the mentioned
d) none of the mentioned
View Answer
Explanation: Spring JDBC framework offers a convenient class, org.springframework.jdbc.core.support.JdbcDaoSupport, to simplify your DAO implementation. This class declares a jdbcTemplate property, which can be injected from the IoC container or created automatically from a data source.
a) True
b) False
View Answer
Explanation: Your DAO class can extend this class to have these methods inherited.
a) setJdbcTemplate()
b) getTemplate()
c) getJdbc()
d) getJdbcTemplate()
View Answer
Explanation: In your DAO methods, you can simply call the getJdbcTemplate() method to retrieve the JDBC template. You also have to delete the dataSource and jdbcTemplate properties, as well as their setter methods, from your DAO class, because they have already been inherited. Again, for simplicity’s sake, only the change to the insert() method is shown.
To practice all areas of Java Spring, here is complete set of 1000+ Multiple Choice Questions and Answers.