Apache Commons DbUtils
From EverybodyWiki Bios & Wiki
Apache Commons DbUtils is a library designed to facilitate easy usage of JDBC (as it is mentioned on its official website).[1][2][3][4][5][6][7][8]
| Developer(s) | Apache Software Foundation |
|---|---|
| Stable release | 1.7
/ July 2017, 20 |
| Repository | https://github.com/apache/commons-dbutils |
| Written in | Java |
| Engine | |
| Operating system | Cross-platform |
| License | Apache License 2.0 |
| Website | commons |
Search Apache Commons DbUtils on Amazon.
Advantages
Some advantages are given below (as mentioned on its official website):
- Less possibility for resource leaks.
- Cleaner, clearer persistence code.
- Automatically populate JavaBean properties from ResultSets. [1]
Scope
DbUtils is designed to cover the following scopes:
- Small - user should be able to understand the whole package in a short amount of time.
- Transparent - user gives it a query, it executes it, and cleans up.
- Fast - user doesn't need to create many temporary objects to work with DbUtils.[1]
Example
Sample code may look like the following:
// 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");
See also
- commons-io on GitHub
References
- ↑ 1.0 1.1 1.2 "DbUtils – JDBC Utility Component". commons.apache.org. Retrieved 2019-08-18.
- ↑ Mirror of Apache Commons DbUtils. Contribute to apache/commons-dbutils development by creating an account on GitHub, The Apache Software Foundation, 2019-08-16, retrieved 2019-08-18
- ↑ baeldung (2017-07-11). "A Guide to Apache Commons DbUtils". Baeldung. Retrieved 2019-08-18.
- ↑ "Java Code Examples org.apache.commons.dbutils.DbUtils". www.programcreek.com. Retrieved 2019-08-18.
- ↑ "org.apache.commons.dbutils.DbUtils java code examples | Codota". www.codota.com. Retrieved 2019-08-18.
- ↑ Oak, Harshad (2008-01-01). Pro Jakarta Commons. Apress. p. 204. ISBN 9781430207177. Search this book on
- ↑ Parsian, Mahmoud (2006-11-08). JDBC Recipes: A Problem-Solution Approach. Apress. p. 598. ISBN 9781430200611. Search this book on
- ↑ Nurkiewicz, Tomasz; Christensen, Ben (2016-10-06). Reactive Programming with RxJava: Creating Asynchronous, Event-Based Applications. "O'Reilly Media, Inc.". p. 237. ISBN 9781491931622. Search this book on
- ↑ "DbUtils – JDBC Utility Component -- Examples". commons.apache.org. Retrieved 2019-08-18.
External links
This article "Apache Commons DbUtils" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:Apache Commons DbUtils. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.
