Use of SQL2O (RPM)

Source: Internet
Author: User

SQL2O is Google's lightweight framework for JDBC encapsulation
The way to use it is simple:
Executeandfetch (Task.class); Returns an entity Class list collection
Addparameter ("FromDate", fromdate); Adding parameters
ExecuteScalar (Integer.class); Returns a single fixed type of parameter
Executescalarlist (Integer.class); Returns the list collection of the underlying type
Executeandfetchtable (). Aslist (); Back to List<map<string,object>>
Executeupdate (); Update the inserted method
|--getkey (); Can get the number of entries modified or inserted
Bind (model); Insert many parameters, one class

Getsingleresult (); Get the first piece of data


About things:
Insert update is the same way
Try (Connection con = sql2o.begintransaction ()) {
Con.createquery (SQL1). Addparameter ("id", idVariable1). Executeupdate ();
Con.createquery (SQL2). Addparameter ("id", idVariable2). Executeupdate ();
Con.commit ();
}


About BULK INSERT:
public void Insertabunchofrows () {
Final String sql = "INSERT into sometable (ID, value) VALUES (: ID,: value)";


Try (Connection con = sql2o.begintransaction ()) {
query query = con.createquery (SQL);


for (int i = 0; i <; i++) {
query.addparameter ("id", i). Addparameter ("Value", "foo" + i)
. Addtobatch ();
}




Query.executebatch (); Executes entire batch
Con.commit (); Remember to call commit (), else sql2o'll automatically rollback.
}

Official documents:

http://www.sql2o.org/docs/spring/

Use of SQL2O (go)

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.