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
