Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

resultset and .first() query

 
Paul Richards
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the following code, could someone please tell me why the rs.first() returns false
and thus never enters the fianl while loop.
I need to know the number of rows in my resultset - is there an easy way to do this?
I am using JdataConnect JDBC driver for SQL server7.

con = dataSource.getConnection();
callStmt = con.prepareCall("{call " + procedure + "}");
callStmt.setString(1,refType);
ResultSet rs = callStmt.executeQuery();
while(rs.next()){
resultSetCount = resultSetCount + 1;
}
rs.first(); // go to the beginning of the resultset
while(rs.next()){
System.out.println(rs.getInt("RefID")
}
cheers
Paul

 
Suji N
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Richards:
In the following code, could someone please tell me why the rs.first() returns false
and thus never enters the fianl while loop.
I need to know the number of rows in my resultset - is there an easy way to do this?
I am using JdataConnect JDBC driver for SQL server7.

con = dataSource.getConnection();
callStmt = con.prepareCall("{call " + procedure + "}");
callStmt.setString(1,refType);
ResultSet rs = callStmt.executeQuery();
while(rs.next()){
resultSetCount = resultSetCount + 1;
}
rs.first(); // go to the beginning of the resultset
while(rs.next()){
System.out.println(rs.getInt("RefID")
}
cheers
Paul


Reply
Hi
At once i faced the same pblm with sql server 2000 database
sql server will accepts same statement "callstmt" for all the related queries.
check in your program that whether u used the same stmt "callstmd" or not ?
otherwise...
send the complete code...
i will send u the reply
Thankyou verymuch
Yours
Suji
 
Michael Fitzmaurice
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Why don't you increment the count and retrieve the next row inside the same while loop, e.g.:
<code>
<pre>
while( rs.next() )
{
System.out.println(rs.getInt("RefID");
resultSetCount++;
}
</pre>
</code>
------------------
"One good thing about music - when it hits, you feel no pain"
Bob Marley
[This message has been edited by Michael Fitzmaurice (edited September 12, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic