how to keep result open after commiting the connection in jdbc with mysql?

Viewed 931

I am using jdbc with mysql and using the transcation. In

while(resultset.hasnext()){}

while I commit the connection my resultset become closed, and when 2nd time loop iterates, it throws Exception that operation can not be performed on closed resultset. While I also set these parameters

statement1 = connection1.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT);

but I am unable to keep ResultSet open after a commit.

while(resultSet.next()){        
    id=resultSet.getInt(1);
     c1 = resultSet.getString(2);
     c2 = resultSet.getDate(3);
     c3 = resultSet.getString(4);
     c4 = resultSet.getString(5);
     c5 = resultSet.getString(6);
     c6 = resultSet.getString(7);
     c7 = resultSet.getString(8);
     c8 = resultSet.getString(9);
     c9 = resultSet.getString(10);
     c10 = resultSet.getString(11);
     c11 = resultSet.getString(12);
     c12 = resultSet.getString(13);
     c13 = resultSet.getString(14);
     c14 = resultSet.getDate(15);
    preparedStatement.setString(1, c1);
    preparedStatement.setDate(2, c2);
    preparedStatement.setString(3, c3);
    preparedStatement.setString(4, c4);
    preparedStatement.setString(5, c5);
    preparedStatement.setString(6, c6);
    preparedStatement.setString(7, c7);
    preparedStatement.setString(8, c8);
    preparedStatement.setString(9, c9);
    preparedStatement.setString(10, c10);
    preparedStatement.setString(11, c11);
    preparedStatement.setString(12, c12);
    preparedStatement.setString(13, c13);
    preparedStatement.setDate(14, c14);
    preparedStatement.executeUpdate();

    query = "UPDATE abc SET isUpdated = 1 WHERE abc_id= "+id;
    statement1.executeUpdate(query);
    System.out.println("holdablity... "+resultSet.getHoldability());
    connection1.commit();
    System.out.println(connection1+"and result is====="+resultSet+" result status is "+resultSet.isClosed()+" connection1 is  "+connection1.isClosed());
    System.out.println("holdablity... "+resultSet.getHoldability());
    connection2.commit();
    System.out.println(connection1+"and result is====="+resultSet+" result status is "+resultSet.isClosed()+" connection2 is  "+connection2.isClosed());
    System.out.println("Data copied........");

    }
1 Answers
Related