jQuery in Action, 2nd edition*
The moose likes JDBC and the fly likes resultset  and .first() query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "resultset  and .first() query" Watch "resultset  and .first() query" New topic
Author

resultset and .first() query

Paul Richards
Greenhorn

Joined: Jul 25, 2001
Posts: 19
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

Joined: Sep 04, 2001
Posts: 35
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

Joined: Aug 22, 2001
Posts: 168
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).]


"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
 
Don't get me started about those stupid light bulbs.
 
subject: resultset and .first() query