DbUtils數(shù)據(jù)庫查詢工具包
原則上這不能說是一個(gè)持久層框架,它提供了一些Jdbc的操作封裝來簡(jiǎn)化數(shù)據(jù)查詢和記錄讀取操作。本站就是采用這個(gè)項(xiàng)目來讀寫數(shù)據(jù)庫,代碼非常簡(jiǎn)潔,如果你厭煩了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://tool.oschina.net/apidocs/apidoc?api=commons-dbutils
本站對(duì) dbutils 做了一個(gè)改進(jìn),下載地址:http://www.oschina.net/uploads/app/commons-dbutils-1.1.fixed.jar
主要解決了dbutils無法處理類似 SELECT userid AS id FROM osc_users 諸如此類的問題,因?yàn)?dbutils 使用的方法是 getColumnName 而不是 getColumnLabel (此問題已經(jīng)在官方的1.3版本中得以解決)。
評(píng)論
圖片
表情
