Link to home
Start Free TrialLog in
Avatar of tfbsr
tfbsr

asked on

reading total number of row with preparedstatement

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
Avatar of pitster
pitster
Flag of United States of America image

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!!!
Avatar of vbStriker
vbStriker

What language are you using?  Most have something like rs1.RecordCount as a function that can be referenced once the rs1 has been populated.
Avatar of tfbsr

ASKER

Using Java
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.
ASKER CERTIFIED SOLUTION
Avatar of TimothyInAfrica
TimothyInAfrica

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial