Spring jdbc templates and best

My question addresses the question of which jdbc template should be used the most commanly, and what are the disadvantages of using the simple jdbc template, although it can be used for both named and owner of question tags, basically explains the difference to me and which is the best to use. as i am new to spring framework.

+3


source to share


1 answer


The JdbcTemplate class executes SQL queries, update statements, and stored procedure calls, iterates over the ResultSets, and retrieves the returned parameter values. It also catches JDBC exceptions and translates them into a generic, more informative exception hierarchy defined in the org.springframework.dao package.

Instances of the JdbcTemplate class are thread safe once configured. This way you can set up one JdbcTemplate instance and then safely insert that shared reference into multiple DAOs.

A common practice when using the JdbcTemplate class is to set up the DataSource in the Spring config file and then add dependencies that the DataSource bean is shared in your DAO classes and the JdbcTemplate is created in the installer for the DataSource.

Spring provides a hibernate pattern and has many advantages such as



1) It removes boiler plate code like getting connection from data source, try / catch block to close connection. This way the developer can focus on writing business logic rather than writing code on paper.

2) Spring hibernateTemplate also throws RunTime exception compared to checkd exception, which allows you to remove the try / catch block entry in each DAO.

3) It also provides a richer template class with which a developer can easily write request code. This templating class also allows you to get the session explicitly, so if the developer wants to get the session object and work with it then this is possible.

which suits you best depending on your requirements.

+4


source







All Articles