Implementation class for the Resultsethandler interface
Keyedhandler (name): Encapsulates each row of data in the result set into a map and then saves the map to a map with the key specified.
public void Testkeyedhandler () throws sqlexception{
Queryrunner runner = new Queryrunner (Dbmanager.getdatasource ());
String sql = "SELECT * from users";
map<integer,map<string,object>> map = (map) runner.query (SQL, new Keyedhandler ("id"));
For (map.entry<integer,map<string,object>> Me:map.entrySet ()) {
int id = Me.getkey ();
map<string,object> Innermap = Me.getvalue ();
For (map.entry<string, object> innerme:innermap.entrySet ()) {
String name = Innerme.getkey ();
Object value = Innerme.getvalue ();
SYSTEM.OUT.PRINTLN (name + "=" + value);
}
}
}
Public Object Query (Connection conn, String sql, object[] params, Resultsethandler rsh) throws SQLException: Performs a query operation in which the Each element value in the object array is used as the permutation parameter for the query statement.
When a database connection is passed in, the programmer is responsible for shutting down the data connection, and the framework automatically closes the connection for you.
Apache-dbutils Framework Development Learning Example