250+ TOP MCQs on JDBC Template and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) 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
Answer: a
Clarification: 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
Answer: b
Clarification: 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
Answer: a
Clarification: 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
Answer: a
Clarification: 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

Answer: b
Clarification: 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
Answer: c
Clarification: 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
Answer: c
Clarification: 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
Answer: c
Clarification: 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
Answer: b
Clarification: 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

Answer: a
Clarification: From the viewpoint of reuse, it’s better to implement the RowMapper interface as a normal class than as an inner class. In the mapRow() method of this interface, you have to construct the object that represents a row and return it as the method’s return value.

11. RowMapper implementation which can automatically map a row to a new instance of the specified class.
a) BeanPropertyRowMapper
b) BeanPropertyRow
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: a
Clarification: 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.

12. Method which provides list of maps.
a) queryForList()
b) update
c) query()
d) all of the mentioned
Answer: a
Clarification: Without the help of RowMapper, you can still call the queryForList() method and pass in a SQL statement. The returned result will be a list of maps. Each map stores a row of the result set with the column names as the keys.

13. Spring JDBC framework offers a convenient class, to simplify your DAO implementation.
a) org.springframework.jdbc.core.support
b) org.springframework.jdbc.core.support.JdbcDaoSupport
c) all of the mentioned
d) none of the mentioned
Answer: b
Clarification: 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.

14. The org.springframework.jdbc.core.support.JdbcDaoSupport class has a setDataSource() method and a setJdbcTemplate() method.
a) True
b) False

Answer: a
Clarification: Your DAO class can extend this class to have these methods inherited.

15. Method to retrieve the JDBC template.
a) setJdbcTemplate()
b) getTemplate()
c) getJdbc()
d) getJdbcTemplate()
Answer: d
Clarification: 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.


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top