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 DataOutputStrea m dos;
static ResultSetMetaDa ta rsInfo;
public static void main(String[] args) {
try
//JDBC
{
Class.forName(" com.ibm.db2.jcc .DB2Driver");
System.out.prin tln("Driver loaded...");
Connection db2Conn = DriverManager.g etConnection("j dbc:db2://id addr/TEST_DB", "user ","pwd");
System.out.prin tln("Conn established..." );
// use a statement to gather data from the database
CallableStateme nt cstmt = db2Conn
.prepareCall("{ ? = CALL ESCRIP.EXPORTDD S(?, ?, ?));
// set the place holders values with appropriate data types
cstmt.registerO utParameter(1, Types.INTEGER);
cstmt.setTimest amp(2, new Timestamp(2006, 04,01,00,00,00, 0));
cstmt.setTimest amp(3,new Timestamp(2006, 05,01,00,00,00, 0));
cstmt.registerO utParameter(4, Types.VARCHAR);
// Execute stored procedure
boolean resultsAvailabl e = cstmt.execute() ;
// Get the return value
final int error = cstmt.getInt(1) ;
System.out.prin tln("error: " + error);
ResultSet rs;
while(true)
{
if(resultsAvail able)
{
rs = cstmt.getResult Set();
long rowcnt = 0;
//count no. of rows
while(rs.next() )
rowcnt++;
System.out.prin tln("No. of rows:"+rowcnt);
}
resultsAvailabl e = cstmt.getMoreRe sults(Statement .KEEP_CURRENT_R ESULT);
if(!resultsAvai lable)
break;
}
resultsAvailabl e = cstmt.getMoreRe sults(Statement .CLOSE_ALL_RESU LTS);
// Close all resources
cstmt.close();
db2Conn.close() ;
}
catch (SQLException sqle) {
sqle.printStack Trace();
}
catch (Exception e) {
e.printStackTra ce();
}
}
}
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 DataOutputStrea m dos;
static ResultSetMetaDa ta rsInfo;
public static void main(String[] args) {
try
//JDBC
{
Class.forName(" com.ibm.db2.jcc .DB2Driver");
System.out.prin tln("Driver loaded...");
Connection db2Conn = DriverManager.g etConnection("j dbc:db2://id addr/TEST_DB", "user ","pwd");
System.out.prin tln("Conn established..." );
// use a statement to gather data from the database
CallableStateme nt cstmt = db2Conn
.prepareCall("{ ? = CALL ESCRIP.EXPORTDD S(?, ?, ?));
// set the place holders values with appropriate data types
cstmt.registerO utParameter(1, Types.INTEGER);
cstmt.setTimest amp(2, new Timestamp(2006, 04,01,00,00,00, 0));
cstmt.setTimest amp(3,new Timestamp(2006, 05,01,00,00,00, 0));
cstmt.registerO utParameter(4, Types.VARCHAR);
// Execute stored procedure
boolean resultsAvailabl e = cstmt.execute() ;
// Get the return value
final int error = cstmt.getInt(1) ;
System.out.prin tln("error: " + error);
ResultSet rs;
while(true)
{
if(resultsAvail able)
{
rs = cstmt.getResult Set();
long rowcnt = 0;
//count no. of rows
while(rs.next() )
rowcnt++;
System.out.prin tln("No. of rows:"+rowcnt);
}
resultsAvailabl e = cstmt.getMoreRe sults(Statement .KEEP_CURRENT_R ESULT);
if(!resultsAvai lable)
break;
}
resultsAvailabl e = cstmt.getMoreRe sults(Statement .CLOSE_ALL_RESU LTS);
// Close all resources
cstmt.close();
db2Conn.close() ;
}
catch (SQLException sqle) {
sqle.printStack Trace();
}
catch (Exception e) {
e.printStackTra ce();
}
}
}