In today's terms Javaweb 8th stage of learning. dbutils technology , Dbutils is a very common function of our database, although later use is its packaging results, but also need to master.
The usual, first use a mind map to show today's blog content.
PS: my mind is used. XMind picture, if you are interested in my mind map and want to see you and the detailed information, please click to download
In addition: if the figure is not clear, please right-click --- opening in a new window is a lot clearer.
A * Overview :
1* definition :
additions and deletions for encapsulation operations database .
* features :
A* read operations for data tables . Span style= "Font-family:times New Roman", He can convert the results to list array , set java collection Easy for programmers to manipulate
b* write operations for data tables , and it became easy . ( just write the SQL statement ).
c* can use data sources , Use JNDI, database connection pooling and other technologies to optimize performance .
two * Common class :
1* Queryrunner class :
1.1* Constructor :
* Queryrunner (): Default no parameter construction .
* Queryrunner (DataSource DS): The construction of the pass-through connection pool .
1.2* Common methods :
* query () Method : used to perform query operations
* query (Connection conn, String sql, resultsethandler<t> rsh, Object ... params)
* Query (String sql, resultsethandler<t> rsh, Object ... params)
* Update () method : used to perform additions, deletions and modifications .
* UPDATE (Connection conn, String sql, Object ... params)
* UPDATE (String sql, Object ... params)
Resultsethandler Interface :
handle (ResultSet Rs) method :
used to add ResultSet conversion of result set types .
three * Two ways of managing transactions :
1* Manually Manage Transactions :
* Queryrunner ()
* Query (Connection conn, String sql, resultsethandler<t> rsh, Object ... params)
* UPDATE (Connection conn, String sql, Object ... params)
* Tool Management Transactions :
* Queryrunner (DataSource DS)
* Query (String sql, resultsethandler<t> rsh, Object ... params)
* UPDATE (String sql, Object ... params)
Four * Resultsethandler:
through the above query statements can be found, every time to implement Resultsethandler the method is very troublesome. In fact , the Resultsethandler interface provides nine implementation classes for use, as follows:
1* Arrayhandler: Turns the first row of data in the result set into an array of objects .
2 * Arraylisthandler: Each row of data in the result set is converted into an array of objects and then stored in the list .
Beanhandler: Encapsulates the first row of data in the result set into a corresponding JavaBean instance .
Beanlisthandler: Encapsulates each row of data in the result set into a corresponding JavaBean instance and stores it in the list in .
5* Maphandler: Encapsulates the first row of data in the result set into a Map , where key is the column name , value is the corresponding value .
6* Maplisthandler: Each row of data in the result set is encapsulated in a Map and then stored in the List.
7* Columnlisthandler: The data from a column in the result set is stored in the list .
8* Keyedhandler: Encapsulates each row of data in the result set into a map , and then the map To a map and its key is the specified column .
9* Scalarhandler: Make a single value query .
Javaweb Learning Notes 8-dbutils Toolkit