Shahid Ghafoor Shahid Ghafoor - 1 month ago 17
Java Question

Total Number of Row Resultset getRow Method

Read the Following Code:

public class selectTable {

public static ResultSet rSet;
public static int total=0;
public static ResultSet onLoad_Opetations(Connection Conn, int rownum,String sql)
int rowNum=rownum;
int totalrec=0;
Statement stmt = Conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String sqlStmt = sql;
rSet = stmt.executeQuery(sqlStmt);
total = rSet.getRow();
catch(Exception e)
System.out.println("Total Number of Records="+totalrec);
return rSet;


The folowing code dos't show actual total:

total = rSet.getRow();

my jTable display 4 record in jTable but total = 0; when I evaluate through debug, it shows:


rather than total=(int)4
And if I use

rSet=last(); above from the code total = rSet.getRow();

then total shows accurate value = 4 but rSet return nothing. then jTable is empty.
Update me!


BalusC's answer is right! but I have to mention according to the user instance variable such as:

total = rSet.getRow();

and then which you are missing


the remaining code is same you will get your desire result.