finished statement db reconnect
This commit is contained in:
parent
605a2ca33d
commit
23df933504
@ -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,13 +136,20 @@ 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 (SQLException e) {
|
} catch (SQLNonTransientConnectionException ee){
|
||||||
e.printStackTrace();
|
if (logintodb(usernamec, passwordc, dbnamec, ipc, portc)) {
|
||||||
}
|
return this.executeQuery(sql);
|
||||||
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update db in some way
|
* update db in some way
|
||||||
@ -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 {
|
||||||
|
try {
|
||||||
|
conn.isValid(5);
|
||||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||||
|
|
||||||
return stmt.executeUpdate();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user