I've just developed my own tiny little JDBC helper library, and I've already realized what a maintenance nightmare it will be.
I'm not looking for a full fledged ORM, like Hibernate, just something light and useful to quickly make JDBC calls passing SQL statements without messing with checked exceptions, closing resources manually, etc...
From your experiencie, can you recommend a nice JDBC helper library?
So far now, I've had a look at Apache Commons DbUtils which seems pretty good. Any other idea?
Here's a list of tools that "ease the pain" when interacting with simple JDBC:
- Spring's JdbcTemplate
- jOOQ (can be used with SQL strings as well - disclaimer: I work for the vendor)
- Apache DbUtils (which you've mentioned yourself)
- JDBI
- sql2o
- persism
There's also ORMLite and MyBatis which are pretty lightweight as well. Using spring and it's rowmappers is pretty easy, but does require you to deal directly with the JDBC. Something like either of the above will hide alot of that away from you, while not being as overly complicated as hibernate.
https://code.google.com/p/jdbc-helper/
Here is the description I copied from its project page:
Inspired by Spring Jdbctemplate and Commons Dbutils projects, JdbcHelper is a very small library for helping the developers code common jdbc operations. JdbcHelper is very lightweight. It is only ~70K and it has no external dependencies.
There is Yank, which is an ultra-light JDBC persistance layer that wraps DBUtils. To use it you create for each table a POJO and a DAO Class. You write your own SQL statements and execute queries through the DBProxy class. You don't have to deal with Connections, ResultSets, and or other low level JDBC code. The Yank jar is only 13 KB as of release 2.0.0, and it depends on only SLF4J, DBUtils, and a 3rd-party database jar, whichever database technology you're using.
Spring Framework (spring-dao) is your friend. If you program your interfaces correctly, later (provided it would be necessary) you can easily switch to something more powerful like Hibernate. Also don't underestimate Hibernate: Native SQL gives you a power of full SQL and still you can benefit from object mapping – something which you will have to program anyway unless you only need to execute the queries as simple as select count(*) from ...
.
In cases where an ORM is not neccessary I use springs JdbcTemplate .
Examples
- http://www.theserverside.com/tip/Database-Access-with-Spring-30-and-the-JdbcTemplate
- http://www.vogella.de/articles/SpringJDBC/article.html