Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how get length or size of Resultset in java [duplicate]

Tags:

java

jdbc

I want to know how many rows in result set after executing the particular query

ResultSet rs = ps.executeQuery();

how get the size of rs??? thanx in advance

like image 475
java baba Avatar asked Jan 17 '26 21:01

java baba


2 Answers

If you just want the number of rows in the ResultSet, you can do :

int size= 0;
if (rs != null)   
{  
  rs.beforeFirst();  
  rs.last();  
  size = rs.getRow();  
}  
like image 113
jester Avatar answered Jan 19 '26 19:01

jester


by doing while loop:

int size=0;
while (rs.next()) {
    size++;
}
like image 25
Baby Avatar answered Jan 19 '26 20:01

Baby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!