@@ -22,7 +22,6 @@ Execute 1000 SELECT statements against a DB and map the data returned to a POJO.
2222| ------------------------------------------| -------------------|
2323| Hand coded <code >ResultSet</code > | 15ms |
2424| [ Sql2o] ( https://github.com/aaberg/sql2o ) | 24ms (60% slower) |
25- | [ JDBI] ( https://github.com/jdbi/jdbi ) | 26ms (73% slower) |
2625
2726## How to use plugin
2827
@@ -37,13 +36,24 @@ Here is very basic example of your MySQL database class:
3736
3837``` java
3938import me.hteppl.data.database.MySQLDatabase ;
39+ import org.sql2o.Connection ;
4040
4141public class MyDatabase extends MySQLDatabase {
4242
4343 public MyDatabase () {
4444 super (" host" , " database" , " user" , " password" );
45- // also you can execute your db scheme with
46- // this.executeScheme("scheme");
45+ // also you can execute your db scheme with
46+ this . executeScheme(" scheme" );
47+
48+ // or use createConnection() method
49+ try (Connection connection = this . createConnection()) {
50+ connection. createQuery(" query" ). executeUpdate();
51+ }
52+
53+ // if you need disable auto commit, use createTransaction() method
54+ try (Connection connection = this . createTransaction()) {
55+ connection. createQuery(" query" ). executeUpdate();
56+ }
4757 }
4858}
4959```
@@ -52,28 +62,43 @@ or SQLite database class:
5262
5363``` java
5464import me.hteppl.data.database.SQLiteDatabase ;
65+ import org.sql2o.Connection ;
5566
5667public class MyDatabase extends SQLiteDatabase {
5768
5869 public MyDatabase () {
5970 super (" database" );
6071 // also you can execute your db scheme with
61- // this.executeScheme("scheme");
72+ this . executeScheme(" scheme" );
73+
74+ // or use createConnection() method
75+ try (Connection connection = this . createConnection()) {
76+ connection. createQuery(... ). executeUpdate();
77+ }
78+
79+ // if you need disable auto commit, use createTransaction() method
80+ try (Connection connection = this . createTransaction()) {
81+ connection. createQuery(... ). executeUpdate();
82+ }
6283 }
6384}
6485```
6586
6687After that, you can easily do what you want with your [ * Sql2o* ] ( https://www.sql2o.org ) connections
6788
6889``` java
69- import me.hteppl.data.Database ;
7090/* import your database class */
7191
7292public class Main {
7393
7494 public static void main (String [] args ) {
75- Database db = new MyDatabase ();
76- db. getConnection(). createQuery(... );
95+ MyDatabase db = new MyDatabase ();
96+ try (Connection connection = db. createConnection()) {
97+ connection. createQuery(... );
98+ }
99+
100+ // or
101+ db. executeScheme(" scheme" );
77102 }
78103}
79104```
0 commit comments