I am getting the Exception with the signature No operations allowed after statement closed.
inside my Java code where I am trying to insert values into the database. The error signature says that my Statement object gets closed and I am trying to use it again in my code , but what I am struggling to understand is why is this happening as I am not closing any connections anywhere in my code.
Here is the Java code.
public class DataBaseAccessUtils {
private static String jdbcUrl =
AppConfig.findMap("BXRequestTracker").get("jdbcUrl").toString();
private static Connection connection = null;
private static Statement statement = null;
public static void insertHostname(String hostname, String rid, String fleet, String locale)
{
locale.toUpperCase();
String sql = "UPDATE " + locale + "REQUESTTRACKER SET " + fleet
+ "='" + hostname + "' WHERE RID='" + rid + "'";
try {
statement.execute(sql);
}
catch (SQLException e) {
e.printStackTrace();
}
}
public static Statement connectToDatabase() {
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(DataBaseAccessUtils.jdbcUrl);
statement = connection.createStatement();
}
catch (Exception e) {
e.printStackTrace();
}
return statement;
}
Also I have observed that the error does not come when there is a single threaded execution , it comes up when multiple threads are trying to update the database simultaneously.