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
-
Easy Database Access with Spring 3.0 and the JdbcTemplate (8 messages)
- Posted by: Cameron McKenzie ( @potemcam )
- Posted on: September 15 2010 11:22 EDT
Threaded Messages (8)
- Easy Database Access with Spring 3.0 and the JdbcTemplate by zart colwin on September 15 2010 15:56 EDT
- DAO Support Classes and the Spring Framework by Cameron McKenzie ( @potemcam ) on September 15 2010 17:12 EDT
- Easy Database Access with Spring 3.0 and the JdbcTemplate by Christian Sell on September 16 2010 08:38 EDT
- Some Other Neat Stuff... by Cameron McKenzie ( @potemcam ) on September 16 2010 08:46 EDT
- There is a lot in spring like this by Daniel Park on September 15 2010 18:44 EDT
- There is a lot in spring like this by Dhrubo Kayal on September 16 2010 02:10 EDT
-
Working with Spring, ResultSets and Custom POJO Mapping by Cameron McKenzie ( @potemcam ) on September 16 2010 08:49 EDT
- Re:Easy Database Access with Spring 3.0 and the JdbcTemplate by Dhrubo Kayal on September 17 2010 12:33 EDT
-
Working with Spring, ResultSets and Custom POJO Mapping by Cameron McKenzie ( @potemcam ) on September 16 2010 08:49 EDT
- There is a lot in spring like this by Dhrubo Kayal on September 16 2010 02:10 EDT
-
Easy Database Access with Spring 3.0 and the JdbcTemplate[ Go to top ]
- Posted by: zart colwin
- Posted on: September 15 2010 15:56 EDT
- in response to Cameron McKenzie ( @potemcam )
Even better: use iBatis in conjunction with the iBatis gear in Spring (SqlMapClientDaoSupport, getSqlMapClientTemplate) and completely forget about JDBC.
ZartC
-
DAO Support Classes and the Spring Framework[ Go to top ]
- Posted by: Cameron McKenzie ( @potemcam )
- Posted on: September 15 2010 17:12 EDT
- in response to zart colwin
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
-
Easy Database Access with Spring 3.0 and the JdbcTemplate[ Go to top ]
- Posted by: Christian Sell
- Posted on: September 16 2010 08:38 EDT
- in response to zart colwin
.. 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.
-
Some Other Neat Stuff...[ Go to top ]
- Posted by: Cameron McKenzie ( @potemcam )
- Posted on: September 16 2010 08:46 EDT
- in response to Christian Sell
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."
-
There is a lot in spring like this[ Go to top ]
- Posted by: Daniel Park
- Posted on: September 15 2010 18:44 EDT
- in response to Cameron McKenzie ( @potemcam )
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.
-
There is a lot in spring like this[ Go to top ]
- Posted by: Dhrubo Kayal
- Posted on: September 16 2010 02:10 EDT
- in response to Daniel Park
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
http://open-garage.blogspot.com/2010/05/part-ii-simple-and-smart-result-mapper.html
-
Working with Spring, ResultSets and Custom POJO Mapping[ Go to top ]
- Posted by: Cameron McKenzie ( @potemcam )
- Posted on: September 16 2010 08:49 EDT
- in response to Dhrubo Kayal
@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)
-
Re:Easy Database Access with Spring 3.0 and the JdbcTemplate[ Go to top ]
- Posted by: Dhrubo Kayal
- Posted on: September 17 2010 00:33 EDT
- in response to Cameron McKenzie ( @potemcam )
@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/