AIR TRAVELS AIR TRAVELS - 7 months ago 32
Java Question

ResultSet not open. Operation 'getString' not permitted. Verify that autocommit is off.?

I am using apache derby and getting the above error here is my code, actually I'm just not getting all the children under the parents, it only give me one level of children, so kindly tell me how to make tree parent and child but this gives only one level of child with above error

getting connection

public static Connection getConnection(){

Connection connection = null;

try {
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();//
//Get a connection
connection = DriverManager.getConnection(dbURL);
connection.setAutoCommit(false);
connection.getAutoCommit();
} catch (Exception except) {
System.out.println(except);
}
return connection;
}


and error in second loop at last reading rs1

Statement stmt;


stmt = MainUI.getConnection().createStatement();

Answer

Nesting the result sets is your problem, I believe.

To have two different result sets open, you must have two separate Statement instances, so each can have its own ResultSet. Otherwise, running the second query on the same Statement instance will close the first ResultSet.

See this answer for more information: http://stackoverflow.com/a/8579669/193453

Also, have a look at the Javadocs for the java.sql.Statement class:

By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists.

Comments