行结果集getRow方法的总数 [英] Total Number of Row Resultset getRow Method
本文介绍了行结果集getRow方法的总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
阅读以下代码:
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();
我的jTable显示4记录在jTable但总计= 0;当我通过调试评估时,它显示:
my jTable display 4 record in jTable but total = 0; when I evaluate through debug, it shows:
total=(int)0;
而不是total =(int)4
如果我使用
rather than total=(int)4 And if I use
rSet=last(); above from the code total = rSet.getRow();
然后total显示准确值= 4但rSet什么都不返回。然后jTable是空的。
更新我!
then total shows accurate value = 4 but rSet return nothing. then jTable is empty. Update me!
推荐答案
BalusC的答案是对的!但我必须根据用户实例变量提及,例如:
BalusC's answer is right! but I have to mention according to the user instance variable such as:
rSet.last();
total = rSet.getRow();
然后你缺少
rSet.beforeFirst();
剩下的代码是相同的,你会得到你想要的结果。
the remaining code is same you will get your desire result.
这篇关于行结果集getRow方法的总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文