Apache-dbutils Framework Development Learning Example

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.