We have a Java class which loops through a result set, which contains Store information, and then starts processing ascii files for each respective stores. For each store to process the ascii file takes around 5 minutes. The issue we encountered is after it processes the first store’s ascii file and then fetches the next result set, we get a SQLException saying “DSRA9110E: ResultSet is closed”.
Our code basically looks like this.
private void startProcess() throws Exception {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement("SELECT STORE_CODE FROM STORE");
rs = pstmt.executeQuery();
while (rs != null && rs.next()) {
System.out.println("Processing store " + rs.getString("STORE_CODE"));
try {
processStoreSalesFile();
} catch (Exception e) {
conn.rollBack();
e.printStackTrace();
}
if (rs != null) {
System.out.println("ResultSet is not null");
}
}
} finally {
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
}
}
When the error occurs, I do see the system printline “ResultSet is not null”. But when it gets the next ResultSet, it says ResultSet is closed.
I have tried to comment out the code which calls processStoreSalesFile() and we didn’t get this error and it is able to fetch the next ResultSet without throwing any exceptions.
The next attempt I tried is to uncomment the call to the method processStoreSalesFile() and then remove any ascii files from the file system so that the program will have nothing to process. And no exceptions thrown also.
Our setup is WebSphere-Informix. We have another setup WebSphere-Oracle and that didn’t have any problems.
The thing I am suspecting is the ResultSet has timedout or it just didn’t want to wait for the process to finish and closed by itself.
Update 1:
Inside the processStoreSalesFile() method, there’s a conn.commit() call to commit the records. Is it when a commit is called, the ResultSet will be closed? At the WAS admin console, I’ve already added the data source property resultSetHoldability with the value ‘1’. But still the ResultSet is closed.
I hope someone can help me here 🙁
Thanks.
Here is what we did which worked. Initially, Websphere was configured to use the Informix JDBC driver as its data source, since we are connecting to an Informix database. We changed it to use the DB2 JCC Driver (as proposed by the IBM Informix tech support) and then in the data source custom property, we set the ‘resultHoldability’ value to ‘1’ (HOLD_CURSORS_OVER_COMMIT). Re-ran the program and it managed to loop through all the results in the result set.