Hello All,

I am getting the following error message when I try to execute my program as an executable jar on a remote system.The same program works perfectly fine on my local system:


Exception in thread "main" java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:794)
at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:7078)
at cbr_beo_3_3.contentbased(cbr_beo_3_3.java:150)
at mainfunction.main(mainfunction.java:32)


Here is my code snippet:

public void contentbased() throws Exception
{

//connecting to the data base
Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection con=DriverManager.getConnection("jdbc:mysql://mysql.cs.abc.edu:3306/dbname","username","password");

Statement stmt=con.createStatement();
Statement stmt1=con.createStatement();
Statement stmt2=con.createStatement();

//result sets for the training data...
//result set containing all rows in tas table
rs2_tas_train=stmt2.executeQuery("SELECT * FROM tas_training;");

//Iterating over the tas training data
//The exception is being thrown here.
while(rs2_tas_train.next())
{
}
}

The mysql server version is 5.1.40 and the mysql-connector-java-bin.jar file version is 5.1.10.Please help me resolve this issue asap.

Edited 6 Years Ago by nav33n: Added [code][/code] tags.

Hello All,

I am getting the following error message when I try to execute my program as an executable jar on a remote system.The same program works perfectly fine on my local system:


Exception in thread "main" java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:794)
at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:7078)
at cbr_beo_3_3.contentbased(cbr_beo_3_3.java:150)
at mainfunction.main(mainfunction.java:32)


Here is my code snippet:

public void contentbased() throws Exception
{

//connecting to the data base
Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection con=DriverManager.getConnection("jdbc:mysql://mysql.cs.abc.edu:3306/dbname","username","password");

Statement stmt=con.createStatement();
Statement stmt1=con.createStatement();
Statement stmt2=con.createStatement();

//result sets for the training data...
//result set containing all rows in tas table
rs2_tas_train=stmt2.executeQuery("SELECT * FROM tas_training;");

//Iterating over the tas training data
//The exception is being thrown here.
while(rs2_tas_train.next())
{
}
}

The mysql server version is 5.1.40 and the mysql-connector-java-bin.jar file version is 5.1.10.Please help me resolve this issue asap.

hi i have got the error too :X
i think it is because if u declare that result set instance as static or after it is pointing to null u are trying to access the result set

but i have learned that there are 2 types of result sets scrollable result set and unscrollable result set i think now u are using unsrollable result set
with scrollable result set we can bring back the pointer after moving it forward

still researching it try to google it hope this helps :-/
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSet.html
u can find some info in above link
and for example
http://www.exampledepot.com/egs/java.sql/CreateScrollableResultSet.html

Edited 6 Years Ago by tizon: n/a

It might help to see what it is you are doing inside that while loop, but I will explain the most likely cause. That being, performing an execute on a statement automatically closes all resultsets associated with that statement so, if you do something like this

Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("sql");
while (rs.next()) {
  s.executeUpdate("some other statement");
}

the rs.next() will throw that error on the first iteration after the reuse of the statement (i.e. in the second iteration).

This article has been dead for over six months. Start a new discussion instead.