finished statement db reconnect

This commit is contained in:
EmilMeindl 2020-04-17 18:28:10 +02:00
parent 605a2ca33d
commit 23df933504

View File

@ -1,5 +1,6 @@
package com.wasteinformationserver.db; package com.wasteinformationserver.db;
import com.mysql.cj.exceptions.ConnectionIsClosedException;
import com.wasteinformationserver.basicutils.Log; import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.basicutils.Storage; import com.wasteinformationserver.basicutils.Storage;
@ -135,12 +136,19 @@ public class JDBC {
*/ */
public ResultSet executeQuery(String sql) { public ResultSet executeQuery(String sql) {
try { try {
conn.isValid(5);
PreparedStatement stmt = conn.prepareStatement(sql); PreparedStatement stmt = conn.prepareStatement(sql);
return stmt.executeQuery(); return stmt.executeQuery();
} catch (SQLNonTransientConnectionException ee){
if (logintodb(usernamec, passwordc, dbnamec, ipc, portc)) {
return this.executeQuery(sql);
} else {
return null;
}
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); return null;
} }
return null;
} }
/** /**
@ -151,9 +159,19 @@ public class JDBC {
* @throws SQLException * @throws SQLException
*/ */
public int executeUpdate(String sql) throws SQLException { public int executeUpdate(String sql) throws SQLException {
PreparedStatement stmt = conn.prepareStatement(sql); try {
conn.isValid(5);
return stmt.executeUpdate(); PreparedStatement stmt = conn.prepareStatement(sql);
return stmt.executeUpdate();
} catch (SQLNonTransientConnectionException ee){
if (logintodb(usernamec, passwordc, dbnamec, ipc, portc)) {
return this.executeUpdate(sql);
} else {
throw new SQLException();
}
} catch (SQLException e){
throw new SQLException();
}
} }
/** /**