469,632 Members | 1,831 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

Help needed Urgently with multiple result sets !!

4
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();
}
}


}
Oct 31 '06 #1
0 2740

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Darko Jovisic | last post: by
28 posts views Thread by stu_gots | last post: by
5 posts views Thread by Stanley Sinclair | last post: by
5 posts views Thread by el prinCipante | last post: by
13 posts views Thread by Gohar | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.