Best practices for Jdbc and configuring JdbcTemplate
Instances of the JdbcTemplate class are thread-safe once configured. As a best practice of configuring the JdbcTemplate in a Spring application, it should be constructed in the constructor injection or setter injection of the data source bean in your DAO classes by passing that data source bean as a constructor argument of the JdbcTemplate class. This leads to DAOs that look, in part, like the following:
@Repository
public class JdbcAccountRepository implements AccountRepository{
JdbcTemplate jdbcTemplate;
public JdbcAccountRepository(DataSource dataSource) {
super();
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
//...
}
Let's see some best practices to configure a database and write
the code for the DAO layer: - If you want to configure the embedded database at the time of development of the application, as the best practice, the embedded database will always...