Sunday, February 4, 2018

Spring JDBC

Spring JDBC is aimed at making it easy to work with data access technologies like JDBC, Hibernate or JPA in a consistent way. This allows us to switch between the above mentioned technologies fairly easy; along with it, one should not worry about how to handle exceptions in each technology.

Spring JDBC has provided a very strong exception hierarchy to handle any technology specific exception into spring jdbc exception or user-defined exception. It provides automatic translation of technology specific exception into spring exceptions like for example a SQLException is translated into its own exception DataAcessException which is the root exception.

In a traditional JDBC, user has to write try-catch-finally blocks to handle the checked SQLException’s. When it comes to spring JDBC without writing this annoying boiler plate code try-catch-block, spring will takes care of catching and handling these, so your code is freed from most of the glue code and you just need to focus on developing your business/persistence logic.

The main advantage of going with spring framework JDBC is you can avoid lot of boiler plate code that you write in a traditional JDBC, and spring jdbc will provide most of the stuff you do for example, creating a connection, statement etc and managing the resources like closing the connection and statements etc. We can better explain the advantages of using spring jdbc in a tabular fashion describing what spring jdbc offers to you and what you need to do.

Thanks for reading. If you like this post please follow us for more updates about technology related updates.

No comments: