Introduction to Spring DAO
All the enterprise applications interact with some database to store and retrieve its data. We have a rich API in Java to interact with the database we all know that Data access through the Java API has many pitfalls. We have to initialize our data access framework, open connections, handle various exceptions, and close connections.So all the DAO frameworks have 2 types of code one is static like creating and closing of connections etc and other one is actual business code which will interact with database. Spring has provided with a rich set of template classes which takes care of the static code in the database interaction. So user only concentrates on the variable part and code will be much cleaner.
Also we understand for all projects the same set of framework can not be used. So Spring DAO has come with variety of different Frameworks that integrate various DAO technologies like JDBC, iBATIS and ORM.
DAO stands for data access object. As the name suggests DAO exist in an application to provide a means to read and write data to the database. The below figure explains how in the Spring DAO service objects interact with the DAO layer.

As we have seen in the figure, the service objects are accessing the DAOs through interfaces. This approach has following advantages.
- It will help the service object to be tested easily as the object is not coupled with specific data access implementation.
- It also helps to expose the relevant methods to the user through interfaces.
- This approach also helps to interchange the DAO framework in the application with minimal changes.
- JDBC only has SQLException and SQLWarnings for Exception handling. So it is very difficult to track the actual issue with the exception and it requires extra efforts in coding. Spring also provide the exception classes like TypeMismatchDataAccessException which helps user to understand the actual issue and solve it quickly.
- Spring also provide templates to reduce the coding effort for databases.
The coming pages will introduce with the Spring JDBC and then we will go in depth with the other API supports in the DAO like iBATIS and ORM tools like Hibernate.
Java Discussion
- - Difference between BMT an
- - Replace getParameterValue
- - Interviewing Next week -
- - Sudoku solver
- - Setting tab order in swin




