Hi,
Following java code returns 24 result sets.It counts number of rows in the first result set correctly.But doesnt count rows from next result set.
When I debugged the code I found out that first time it enters in the loop while(rs.next()).But from the next result set it doesn't enter that loop as rs.next() returns false.DB2 is used as backend.
thanx 4 help.
import java.sql.*;
import java.io.*;
public class exportdds33 {
static DataOutputStream dos;
static ResultSetMetaData rsInfo;
public static void main(String[] args) {
try
//JDBC
{
Class.forName("com.ibm.db2.jcc.DB2Driver");
System.out.println("Driver loaded...");
Connection db2Conn = DriverManager.getConnection("jdbc:db2://id addr/TEST_DB", "user ","pwd");
System.out.println("Conn established...");
// use a statement to gather data from the database
CallableStatement cstmt = db2Conn
.prepareCall("{? = CALL ESCRIP.EXPORTDDS(?, ?, ?));
// set the place holders values with appropriate data types
cstmt.registerOutParameter(1, Types.INTEGER);
cstmt.setTimestamp(2, new Timestamp(2006,04,01,00,00,00,0));
cstmt.setTimestamp(3,new Timestamp(2006,05,01,00,00,00,0));
cstmt.registerOutParameter(4, Types.VARCHAR);
// Execute stored procedure
boolean resultsAvailable = cstmt.execute();
// Get the return value
final int error = cstmt.getInt(1);
System.out.println("error: " + error);
ResultSet rs;
while(true)
{
if(resultsAvailable)
{
rs = cstmt.getResultSet();
long rowcnt = 0;
//count no. of rows
while(rs.next())
rowcnt++;
System.out.println("No. of rows:"+rowcnt);
}
resultsAvailable = cstmt.getMoreResults(Statement.KEEP_CURRENT_RESULT );
if(!resultsAvailable)
break;
}
resultsAvailable = cstmt.getMoreResults(Statement.CLOSE_ALL_RESULTS);
// Close all resources
cstmt.close();
db2Conn.close();
}
catch (SQLException sqle) {
sqle.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
}
}