I have a JDBC MySQL connection in Java. My program works fine for simple execution of query.
If I run the same program for more than 10 hours and execute a query then I receive the following MySQL exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Connection.close() has already been called. Invalid operation in
this state.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(
Native Method)
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
No operations allowed after statement closed.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(
Native Method)
I have not used close()
method anywhere. I created database connection and opened it forever and always executed query. There is no place where I explicitly mentioned timeout for connection. I am unable to identify the problem.
Here is the code I use for the database connection:
String driver = PropertyReader.getDriver();
String url = dbURLPath;
Class.forName(driver);
connectToServerDB = DriverManager.getConnection(url);
connectToServerDB.setAutoCommit(false);
What causes that exception?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…