I'm calling a Sybase stored procedure that returns multiple resultsets through JDBC. I need to get a specific result set that has a column named "Result" This is my code :
CallableStatement cs = conn.prepareCall(sqlCall);
cs.registerOutParameter(1, Types.VARCHAR);
cs.execute();
ResultSet rs=null;
int count = 1;
boolean flag = true;
while (count < 20000 && flag == true) {
cs.getMoreResults();
rs = cs.getResultSet();
if (rs != null) {
ResultSetMetaData resultSetMetaData = rs.getMetaData();
int columnsCount = resultSetMetaData.getColumnCount();
if (resultSetMetaData.getColumnName(1).equals("Result")) {
// action code resultset found
flag = false;
// loop on the resultset and add the elements returned to an array list
while (rs.next()) {
int x = 1;
while (x <= columnsCount) {
result.add(rs.getString(x));
x++;
}
}
result.add(0, cs.getString(1));
}
}
count++;
}
What happens here is that cs.getMoreResults
returns a lot of null resultsets till it reaches the target one. I can't use cs.getMoreResults
as loop condition because it returns false for null resultsets.
I put a fixed number to end the loop in condition the wanted result set wasn't returned to prevent it from going into infinite loop. It worked fine but I don't think this is right.
I think the null resultsets returned from the assignment in Sybase select @variable = value
Has anyone faced this before?