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)