Skip to content

Commit 3849558

Browse files
Reusable database connection and warped missed resources with try
1 parent 338a81f commit 3849558

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/main/java/org/maxgamer/quickshop/database/DatabaseManager.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,17 @@ private void init() throws ConnectionException {
110110
*/
111111
boolean hasTable(@NotNull String table) throws SQLException {
112112
DatabaseConnection connection = database.getConnection();
113-
ResultSet rs = connection.get().getMetaData().getTables(null, null, "%", null);
114113
boolean match = false;
115-
while (rs.next()) {
116-
if (table.equalsIgnoreCase(rs.getString("TABLE_NAME"))) {
117-
match = true;
118-
break;
114+
try (ResultSet rs = connection.get().getMetaData().getTables(null, null, "%", null)) {
115+
while (rs.next()) {
116+
if (table.equalsIgnoreCase(rs.getString("TABLE_NAME"))) {
117+
match = true;
118+
break;
119+
}
119120
}
121+
} finally {
122+
connection.release();
120123
}
121-
rs.close();
122-
connection.release();
123124
return match;
124125
}
125126

@@ -163,8 +164,9 @@ private synchronized void runTask() { // synchronized for QUICKSHOP-WX
163164
return;
164165
}
165166
DatabaseConnection dbconnection = this.database.getConnection();
166-
167-
try (Connection connection = dbconnection.get()) {
167+
//We do not close the connection since is reusable
168+
Connection connection = dbconnection.get();
169+
try {
168170
//start our commit
169171
connection.setAutoCommit(false);
170172
Timer ctimer = new Timer(true);

0 commit comments

Comments
 (0)