总行数结果集 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 在 jTable 中显示 4 条记录,但总数 = 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();
然后总计显示准确值 = 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屋!
查看全文