Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to get number of rows in recordset but getRow() returning -3

Status
Not open for further replies.

Sarky78

Programmer
Oct 19, 2000
878
GB
Hi all,

I really hope someone here will be able to help me with this, it is driving me mad.

I have a query that is returning records within SQL Server, and i am trying to get the number of records returned for checks within my code. this is what i have at the moment:

Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection con = DriverManager.getConnection(url, username, password);

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs_item;

rs_item = stmt.executeQuery("select TOP 1 ColA, ColB from DATA_TBL_9");

rs_item.last();
int num_recs = rs_item.getRow();
out.println(num_recs); <-- this returns -3 everytime!!!!

I've tried doing:

while (rs_item.next()) {
out.println(rs_item.getRow() + "<br />");
}

and this increments as expected.

I've read somepeople saying to do a count(*) before each query and to use that, but i am going to have 9 queries running on this page, so would like to use the above method if available to minimize hits on the database, i don't really want to have 18 queries running.

Any ideas?

TIA

Tony
 
Well, java.sql.ResultSet is an interface. So, what implementation are you using? Do you have that source? Thats where I'd start.

-----------------------------------------
I cannot be bought. Find leasing information at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top