Apachecommons Dbutils is an open source JDBC tool class library provided by the Apache organization, which encapsulates the traditional operations database class two times and can convert the result set to a list.
The latest version is now 1.6.
The official website address is: http://commons.apache.org/proper/commons-dbutils/
Dbutils is a small JDBC lightweight package, the core of which is the encapsulation of the result set, which can encapsulate the result set of the query directly into JavaBean, which is the most tedious and error-prone part of our work.
Before using dbutils, you should be aware of some issues:
1. Dbutils is a simple package of JDBC and can be used in combination with JDBC.
2, dbutils to the result set automatic encapsulation for JavaBean is a strict requirement: must meet the JavaBean specification, followed by the Bean getter and setter method name and the result set column name one by one corresponds, Private members of JavaBean are not required to correspond to table result set column name one by one.
3, Dbutils can be encapsulated as a result set of various types, mainly: bean/list<bean>,map/list<map>/map<map>, array/list< array, column/list <, these types.
4, dbutils Do insert operation, cannot return the self-increment primary key, can be implemented by a workaround, such as to get a sequence, and then put the sequence into the database, and return this sequence.
5, Dbutils performance and JDBC performance is the same, the testing process did not find performance loss, has a high performance, but without losing the flexibility of JDBC.
Dbutils class
A class that provides useful methods for general work, such as closing a connection, loading a JDBC driver, and all of its methods are static.
A:loaddriver (Stringdriveclassname): This method loads and registers the JDBC driver and returns true if successful, without the need to catch the classnotfoundexception exception. Determines whether the driver was loaded successfully by the return value.
B:close method: The Dbutils class provides three overloads for the shutdown method. These methods check that the supplied arguments are NOT NULL, and if not, they close the connection (Connection), Declaration (Statement), or result set (ResultSet) object.
...
Queryrunner class
This class simplifies the SQL query, which is combined with Resultsethandler (described later in the interface) to accomplish most of the database operations, greatly reducing the number of encodings
"Constructor (1): Queryrunner () (2): Queryrunner (Datasource ds)".
A:query (Connectionconn, String sql, Object[]params, Resultsethandler rsh) Method: This method executes a select query with parameters, in this query, The value of the object array is used as the replacement parameter for the query. This approach internally handles the creation and closing of PreparedStatement and resultset. The Resultsethandler object transforms data from resultset into an easier or application-specific format to use.
Resultsethandler interface
As its name implies, this interface performs processing of a java.sql.ResultSet, transforms and processes the data into any form, which is beneficial to its application and easier to use. This component provides a
Arrayhandler: Converts data from the first row in resultset into an array of objects
...
To summarize, it is actually three main functions:
1. Connect and close the database;
2. Database processing;
3. Result processing
Apache Commons's Dbutils profile