Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
234 views
Welcome To Ask or Share your Answers For Others

1 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...