Lightweight JDBC helper library alternative to Apa

2019-01-10 18:12发布

问题:

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?

回答1:

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


回答2:

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.



回答3:

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.



回答4:

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.



回答5:

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 ....



回答6:

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