Although there is not much overhead in creating the new JdbcTemplate, not so much. The JdbcDaoSupport class, an abstract class useful for processing DAOs based on JdbcTemplate, sequentially allows each DAO to either enter a DataSource (and creates an instance of JdbcTemplate based on this DataSource under the shell) or enter JdbcTemplate. Since you can do this, you will either do the latter only if you want to customize your JdbcTemplate by setting one or more of the following properties:
- Fetchsize
- ignoreWarnings
- maxRows
- nativeJdbcExtractor
- QueryTimeout
- skipResultsProcessing
- exceptionTranslator
You will likely have one JdbcTemplate for each combination of these properties. They all have default values, so you only need to set it if you are going to override them. Depending on the variety of your DAOs, you may have one or more. Or, in the case of the JdbcDaoSupport extension, you might not have a single one, as each DAO simply wraps the default JdbcTemplate data source under the covers.
source share