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.

Recommended Answers

All 2 Replies

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

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.