原则上这不能说是一个持久层框架,它提供了一些Jdbc的操作封装来简化数据查询和记录读取操作。本站就是采用这个项目来读写数据库,代码非常简洁,如果你厌烦了Hibernate的庞大,不妨可以试试——DbUtils。
给出一小段代码看看DbUtils是怎么用的:
QueryRunner run = new QueryRunner(dataSource);
// Use the BeanHandler implementation to convert the first
// ResultSet row into a Person JavaBean.
ResultSetHandler h = new BeanHandler(Person.class);
// Execute the SQL statement with one replacement parameter and
// return the results in a new Person object generated by the BeanHandler.
Person p = (Person) run.query("SELECT * FROM Person WHERE name=?", "John Doe", h);
JavaDoc:http://www.oschina.net/uploads/doc/commons-dbutils-1.1/index.html
本站对 dbutils 做了一个改进,下载地址:http://www.oschina.net/uploads/app/commons-dbutils-1.1.fixed.jar
主要解决了dbutils无法处理类似 SELECT userid AS id FROM osc_users 诸如此类的问题,因为 dbutils 使用的方法是 getColumnName 而不是 getColumnLabel 。