I have tried many ways but always i'm getting this error.
Actually i'm trying to access result set values from other class and for Database Query i have created a separate class.
Please do not mark this as previously asked because i got the solution only of single class.
This is my DBVerification class
public class DBVerification {
private static String DB_URL = PropertyManager.getInstance().getDB_URL();
private static String DB_USER= PropertyManager.getInstance().getDB_USER();
private static String DB_PASSWORD= PropertyManager.getInstance().getDB_PASSWORD();
private static String DBClass= PropertyManager.getInstance().getDBClass();
private static Connection connection;
public static ArrayList<ResultSet> executeStoredProcedure(String query) throws ClassNotFoundException, SQLException
{
ArrayList<ResultSet> resultset = new ArrayList<ResultSet>();
Class.forName(DBClass);
connection= DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
CallableStatement cstmt = connection.prepareCall( "{ call " + query+" }" );
//System.out.println("{ call " + query+" }");
try {
boolean results = cstmt.execute();
int rsCount = 0;
do {
if(results) {
ResultSet rs = cstmt.getResultSet();
resultset.add(rs);
rsCount++;
System.out.println("RESULT SET #" + rsCount);
// rs.close();
}
System.out.println();
results = cstmt.getMoreResults();
} while(results);
//cstmt.getMoreResults(Statement.KEEP_CURRENT_RESULT);
//cstmt.close();
}
catch (Exception e) {
e.printStackTrace();
}
return resultset;
}
public static void closeDB() throws SQLException
{
connection.close();
}
}
This is my second class Reimbursement class
public class Reimbursement
{
ArrayList<ResultSet> result = DBVerification.executeStoredProcedure("getreimbursements");
for (ResultSet curInstance: result) {
if(result.indexOf(curInstance) == 0)
{
while(curInstance.next())
{
String branchName=curInstance.getString("BranchName");
String department=curInstance.getString("DepartmentName");
String employee=curInstance.getString("EmployeeName");
String title=curInstance.getString("Title");
String claimdate=ValueConverter.DateFormat(curInstance.getString("Date"));
}
curInstance.close();
}
if(result.indexOf(curInstance) == 1)
{
while(curInstance.next())
{
String category=curInstance.getString("Category");
String expensedate=ValueConverter.DateFormat(curInstance.getString("ExpenseDate"));
String description=curInstance.getString("Description");
String approvedby=curInstance.getString("ApprovedBy");
}
curInstance.close();
}
}
DBVerification.closeDB();
}
Please do not look for main method because this is for testing class so i'm already using this class in my xml file.
Please give me suggestion that what i'm doing wrong it give me error message that 'The result set is closed'.
Image of exception actually it is my test class so it will display error only in this form i have edited the line which was indicated
exception message