In today's terms Javaweb 8th stage of learning.
dbutils Technology , Dbutils is a very common function of our database, although later use is the result of its encapsulation, 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 :
* read operation for data table 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 Function :
* 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)
???? 1.3* 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 :
2.1* 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: Turns each row of data in the result set into an array of objects , and store it in List in .
?
Beanhandler: Encapsulates the first row of data in the result set into a corresponding JavaBean in the instance .
Beanlisthandler: Encapsulates each row of data in the result set into a corresponding JavaBean in the instance , stored in List in .
?
5* Maphandler: Encapsulates the first row of data in the result set into a Map in , Key is a column name , Value is the corresponding value .
6* Maplisthandler: Encapsulates each row of data in the result set into a Map in , and then store it in List.
?
7* Columnlisthandler: Stores data from a column in the result set to List in .
?
8* Keyedhandler: Encapsulates each row of data in the result set into a Map in , and put these Map and save it to a Map in , its Key for the specified column .
9* Scalarhandler: Making a single value query .
Javaweb Learning Notes 8-dbutils Toolkit