Resultset not open. Verify Autocommit is OFF. Apache Debry

for me, it was the Connection object that got closed. so next time think about using your existing Connection object.

instead, I Use this everytime I make a new Query.

 private Connection getConnect() {
    try {
        return DriverManager.getConnection(Utils.getDatabaseConnection(), null);
    } catch (SQLException e) {
        e.printStackTrace();
        return null;
    }
}

and then do whatever with null check for ex.

getConnect().createStatement();


The problem is that you have closed your query before reading your resultset. Closing the query, closes the resultset, hence why you get the "ResultSet not open" error. You should close the query right at the end, in a finally block:

ResultSet word;

Statement query=null;

String getData="SELECT THEWORD FROM MAINTAB";
try{
    System.out.println(dbconn.getAutoCommit());
    query = dbconn.createStatement();
    word = query.executeQuery(getData);


    dbconn.setAutoCommit(false);
    System.out.println(dbconn.getAutoCommit());

    for(;word.next();)
        System.out.println(word.getString(1));

}catch(Throwable e){
    System.out.println("Table fetch failed or result data failed");
} finally{
    if(query!=null) {
        try {
             query.close();
        }
        catch(SQLException ex) {
              System.out.println("Could not close query");
        }
   }
}

Tags:

Sql

Java

Derby