我用过一个ResultSet返回一定数量的行.我的代码是这样的:
ResultSet res = getData();
if(!res.next())
{
System.out.println("No Data Found");
}
while(res.next())
{
// code to display the data in the table.
}
Run Code Online (Sandbox Code Playgroud)
有没有方法可以检查返回的行数ResultSet?或者我必须自己写?
阅读以下代码:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
下面的代码不显示实际总数:
total = rSet.getRow();
Run Code Online (Sandbox Code Playgroud)
我的jTable显示4记录在jTable但总计= 0; 当我通过调试评估时,它显示:
total=(int)0;
Run Code Online (Sandbox Code Playgroud)
而不是总数=(int)4如果我使用
rSet=last(); above from the code total = rSet.getRow();
Run Code Online (Sandbox Code Playgroud)
总计显示准确值= 4但rSet什么都不返回.然后jTable是空的.告诉我!