Apache Commons DbUtils 1.5 发布
openkk 12年前
<p><a href="/misc/goto?guid=4958195654698314880" target="_blank">DbUtils </a>刚发布的 1.5 版本改进记录包括:</p> <p><strong>Bug</strong><br /> [DBUTILS-73] - .BasicRowProcessor.CaseInsensitiveHashMap uses default Locale for toLowerCase<br /> [DBUTILS-77] - "drop view" does not work from QueryRunner.update with SQLServer JDBC drivers. Same SQL works with a PreparedStatement just fine.<br /> [DBUTILS-93] - Source assembly artifact fails to build a site because of missing pmd-ruleset.xml<br /> <br /> <strong>改进</strong><br /> [DBUTILS-66] - ScalarHandler, ColumnHandler and KeyedHandler are missing generics<br /> [DBUTILS-84] - BeanProcessor method processColumn should take SQLXML in consideration<br /> [DBUTILS-91] - Enhance BasicRowProcessor to have row mapping easier to configure<br /> <br /> <strong>新特性</strong><br /> [DBUTILS-67] - Add a BeanMapHandler<br /> [DBUTILS-76] - New handler StringColumnListHandler<br /> <br /> <strong>任务</strong><br /> [DBUTILS-88] - Make AsyncQueryRunner be a decorator around a QueryRunner<br /> <br /> <strong>测试</strong><br /> [DBUTILS-94] - Provide test coverage for org.apache.commons.dbutils.DbUtils</p> <p> Common Dbutils是操作数据库的组件,对传统操作数据库的类进行二次封装,可以把结果集转化成List。 </p> <div class="spctrl"></div> <p> 补充一下,传统操作数据库的类指的是JDBC(java database connection:java数据库连接,java的数据库操作的基础API。)。 <br /> <br /> 特色: </p> <div class="spctrl"></div> <p> 1.对于数据表的读操作,他可以把结果转换成List,Array,Set等java集合,便于程序员操作; </p> <div class="spctrl"></div> <p> 2.对于数据表的写操作,也变得很简单(只需写sql语句) </p> <div class="spctrl"></div> <p> 3.可以使用数据源,使用JNDI,数据库连接池等技术来优化性能--重用已经构建好的数据库连接对象,而不像php,asp那样,费时费力的不断重复的构建和析构这样的对象。 </p> <div class="spctrl"></div> <p> DBUtils是java编程中的数据库操作实用工具,小巧简单实用, 给出一小段代码看看DbUtils是怎么用的:<br /> </p> <pre class="brush:java; toolbar: true; auto-links: false;">// Create a ResultSetHandler implementation to convert the // first row into an Object[]. ResultSetHandler<Object[]> h = new ResultSetHandler<Object[]>() { public Object[] handle(ResultSet rs) throws SQLException { if (!rs.next()) { return null; } ResultSetMetaData meta = rs.getMetaData(); int cols = meta.getColumnCount(); Object[] result = new Object[cols]; for (int i = 0; i < cols; i++) { result[i] = rs.getObject(i + 1); } return result; } }; // Create a QueryRunner that will use connections from // the given DataSource QueryRunner run = new QueryRunner(dataSource); // Execute the query and get the results back from the handler Object[] result = run.query( "SELECT * FROM Person WHERE name=?", h, "John Doe"); </pre>