Shahid Ghafoor Shahid Ghafoor - 17 days ago 8
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;
try
{
Conn=ConnectionODBC.getConnection();
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(e.getMessage());
}
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:

total=(int)0;


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!

Answer

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

rSet.last(); 
total = rSet.getRow();

and then which you are missing

rSet.beforeFirst();

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