[DBUtils database connection pool multi-table join query]

DBUtils database connection pool multi-table join query
using MapListHandler of (specific use to view the official documentation http://commons.apache.org/proper/commons-dbutils/apidocs/index.html)
Key - sql statement to query the field of
value- - the results of a database query to get the
problem description
for multi-table join query, if you use BeanListHandler, null pointer exception occurs.
For example the package is classified employee and department Javabean. employee declared target of a department. As shown below:


Solution
using MapListHandle eventually return List <map <String, Object >> , removed using an iterative manner by the query field value, the corresponding value is first taken out from the map in accordance with the Department class key, and the package as the Department object. And eventually packaged as an Employee object, this would resolve the use BeanListHandler null pointer abnormal phenomenon.
Specific codes are as follows FIG.

ResultSetHandler implementation class introduced (provided by the frame DbUtils)

 

     Note: DbUtils provides us with 10 ResultSetHandler implementation class, they are:

     ①ArrayHandler: the first row of data query results saved to an array Object

     ②ArrayListHandler results of the query, the first row of each package array to the Object, and then stores the data in a set of List

     The first row of data ③BeanHandler query results, the user object to the package

     Each row ④BeanListHandler package query results to user object, and then stored in a set of List

     ⑤ColumnListHandler data specified query result column set encapsulated List

     ⑥MapHandler the first row of data query result to map binding package (key == column name, value == column values)

     ⑦MapListHandler Each row of the query result set into map package (key == column name, value == column values), then the map set into a set of List

     Each row of data ⑧BeanMapHandler query result, encapsulated into the User object, and then set into mao (key == column name, value == column values)

     Each row of data ⑨KeyedHandler query result, encapsulated map1 (key == column name, value == column values), then set the map1 (plurality) into map2 set (only one)

     Results of a similar package ⑩ScalarHandler count, avg, max, min, sum ...... function

Published 81 original articles · won praise 43 · views 50000 +

Guess you like

Origin blog.csdn.net/Mrchai521/article/details/104011607