Easy Database Access with Spring 3.0 and the JdbcTemplate


News: Easy Database Access with Spring 3.0 and the JdbcTemplate

  1. The Spring approach to database access is simple. Don't get distracted by the IoC, DI or aspect oriented features of the Spring container. You can leverage the features of Spring's JdbcTemplate and their overall approach to database access without having to delve into any of the much touted features of the Spring framework.

    An Easy Approach to Learning Spring's Data Access Philosophy: An Introductory Tutorial

  2. Even better: use iBatis in conjunction with the iBatis gear in Spring (SqlMapClientDaoSupport, getSqlMapClientTemplate) and completely forget about JDBC.


  3. We'll be getting around to coverage on the Spring DAO classes eventually! If you'd like to take this example and demonstrate such an implementation, we could probably speed up the publishing of that article immensely!

    This is a good introduction to the basics of database access. We're going to build from here.

    cmckenzie at techtarget dot com

  4. .. or use a decent O/R mapper like Hibernate, or any JPA implementation, and forget about both JDBC and Spring. I am amazed how someone can market a thin code wrapper on top of JDBC (thats hwat JdbcTemplate is IMO) as a framework and get away with that. Looks to me like that someone once wrote a JDBC app, creating some utility functions on the way, and then wrapped them up under said name.

  5. Some Other Neat Stuff...[ Go to top ]

    Certainly from this tutorial, the JdbcTemplate looks like it's just a thin wrapper around JDBC. Heck, maybe even from some advanced tutorials it would look like that too. In a future tutorial we'll also see how this works with the various unchecked exceptions Spring will throw if there is a problem, so that's a neat benefit to using the JdbcTemplate - not only that it 'wraps' up the checked SqlException, but also that it can rethrow various meaningful unchecked exceptions to which you can respond. Of course, it's also the first step in moving towards using some of the Spring DAO classes as well, although, you might argue they are simply wrappers around the basic DAO design pattern.

    So, just some simple classes that make life a bit easier and wrap some moderately tricky code and force people into using standard design patterns? Perhaps that's all it is. Still, when so many people complain that Spring is too complicated, or that it's too confusing to learn, it's actually a good thing to be able to step back from all of the DI and IoC and other projects and say "you know what, there's really nothing going on there that's all that complicated."

  6. There is a lot in spring like this[ Go to top ]

    There are lot of features in Spring that are handy without the DI containter the JDBC template is probably one of the most compelling. 

    Another one thats handy is the JNDI Object factory for when spring or the continer is not doing the lookup (I admit this use is less relevant since EJB3)

    The assert is also handy for null check where you dont want to write 2/3 lines to check null and throw an illegal argument exception.

    Anything in spring that can be used with the container can also be used as pojos.



  7. There is a lot in spring like this[ Go to top ]

    Cameon - thanks for putting to light spring jdbc again. Its a very good framework. I had highlighted this in an article in 2006 - http://www.oracle.com/technetwork/articles/entarch/spring-jdbc-dao-101284.html

    Now one limitation with Spring JDBC is externalized query and data mapper. So your list and finders tend to be of some length. Here is a solution to that


  8. @Dhrubo

    I agree. The task of taking a result and mapping back to a POJO from a query can be a tad more involved. A follow up tutorial will go over all four basic CRUD operations, with the query and mapping back to the GameSummary class being part of it. I may steal an image or two from those tutorials and use them as a reference. :)

    (Good Work)


  9. @Cameron

    Please continue with the posts. Since we are all OS fans, please feel free to use/reuse. If you go through my posts you will see how we can simplify externalization and mapping using Sql aliases and Bean mapping utility called JODD. Its on Maven 2 repository and you can see JODD here - http://jodd.org/