66
77import javax .sql .rowset .CachedRowSet ;
88import javax .sql .rowset .RowSetProvider ;
9- import java .sql .PreparedStatement ;
10- import java .sql .ResultSet ;
11- import java .sql .SQLException ;
12- import java .sql .Statement ;
9+ import java .sql .*;
1310
1411/**
1512 * @author <a href="https://github.com/Cobeine">Cobeine</a>
1613 */
1714
1815public class PreparedQuery {
1916 private final MySQLConnection sqlConnection ;
17+ private Connection connection ;
2018 private PreparedStatement statement ;
2119 boolean batched ;
2220 public PreparedQuery (@ NotNull MySQLConnection sqlConnection , @ NotNull String buildQuery ) {
2321 this .sqlConnection = sqlConnection ;
2422 try {
25- this .statement = sqlConnection .getConnection ().getConnection ().prepareStatement (buildQuery );
23+ this .connection = sqlConnection .getConnection ().getConnection ();
24+ this .statement = connection .prepareStatement (buildQuery );
2625 } catch (SQLException e ) {
2726 sqlConnection .getLogger ().severe (String .format ("Failed to prepare statement of query '%s': %s" , buildQuery , e ));
2827 }
@@ -47,9 +46,9 @@ public int[] executeBatch() throws SQLException {
4746 statement .close ();
4847 }
4948
50- if (sqlConnection . getConnection () != null ) {
51- sqlConnection . getConnection (). getConnection () .commit ();
52- sqlConnection . getConnection () .close ();
49+ if (connection != null ) {
50+ connection .commit ();
51+ connection .close ();
5352 }
5453 }
5554 }
@@ -82,8 +81,8 @@ public int executeUpdate() throws SQLException {
8281 if (statement != null && !statement .isClosed ())
8382 statement .close ();
8483
85- if (sqlConnection . getConnection () != null )
86- sqlConnection . getConnection () .close ();
84+ if (connection != null )
85+ connection .close ();
8786
8887 }
8988 }
@@ -102,8 +101,8 @@ public int executeUpdateWithKeys() throws SQLException {
102101 if (statement != null )
103102 statement .close ();
104103
105- if (sqlConnection . getConnection () != null )
106- sqlConnection . getConnection () .close ();
104+ if (connection != null )
105+ connection .close ();
107106
108107 }
109108 }
@@ -120,8 +119,8 @@ public ResultSet executeQuery() throws SQLException {
120119 if (statement != null && !statement .isClosed ())
121120 statement .close ();
122121
123- if (sqlConnection . getConnection () != null )
124- sqlConnection . getConnection () .close ();
122+ if (connection != null )
123+ connection .close ();
125124
126125 }
127126 return rowSet ;
@@ -146,8 +145,8 @@ public void executeUpdateAsync(final Callback<Integer, SQLException> callback) {
146145 private void addBatch () throws SQLException {
147146 if (batched )
148147 return ;
149- if (sqlConnection . getConnection (). getConnection () .getAutoCommit ()) {
150- sqlConnection . getConnection () .setAutoCommit (false );
148+ if (connection .getAutoCommit ()) {
149+ connection .setAutoCommit (false );
151150 }
152151 statement .addBatch ();
153152 batched = true ;
@@ -190,7 +189,7 @@ public void executeQueryAsync(final Callback<ResultSet, SQLException> callback)
190189 }
191190 @ SuppressWarnings ("unused" )
192191 public void rollback () throws SQLException {
193- if (sqlConnection . getConnection () != null )
194- sqlConnection . getConnection (). getConnection () .rollback ();
192+ if (connection != null )
193+ connection .rollback ();
195194 }
196195}
0 commit comments