?
Solved

reading total number of row with preparedstatement

Posted on 2006-04-26
5
Medium Priority
?
275 Views
Last Modified: 2010-04-17
Expert Exchange

Is there a way to read the total number of rows from a select satement using prepared statement, instead of having to loop throght the data and count as you go?
 rs1 = getIP.getResultSet();
 while (rs1.next())
    packIP(rs1.getString(1));

but instead

int total =  command

Thanks
0
Comment
Question by:tfbsr
5 Comments
 
LVL 3

Expert Comment

by:pitster
ID: 16547336
You can try:
Select Count(myTable.*) as Total
From myTable

That should return 1 row with a value and a column header 'Total'



Good Luck!!!
0
 
LVL 2

Expert Comment

by:vbStriker
ID: 16558934
What language are you using?  Most have something like rs1.RecordCount as a function that can be referenced once the rs1 has been populated.
0
 

Author Comment

by:tfbsr
ID: 16564505
Using Java
0
 
LVL 2

Expert Comment

by:vbStriker
ID: 16566048
Sorry - don't know much about Java.  pitster's initial response will work for any query language so if you can't find another way it should get you there.
0
 

Accepted Solution

by:
TimothyInAfrica earned 200 total points
ID: 16576999
Hello,

I suggest you set the result set to last and then you get the row number, this should give you the number of rows that was selected with your statement.

 rs1 = getIP.getResultSet();
 rs1.last();
 int rows = rs1.getRow()

//if  you need to go to the first again
rs1.first();

Hope this helps.

Cheers

Timothy
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Starting up a Project

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question