相关疑难解决方法(0)

行结果集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;
    }

}
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是空的.告诉我!

java jdbc

19
推荐指数
3
解决办法
12万
查看次数

如何在ResultSet中查找记录数

我正在ResultSet查询Oracle查询.当我ResultSet在无限循环中迭代它时.

ResultSet rs = (ResultSet) // getting from statement
while (rs.next()) {
//
//
}
Run Code Online (Sandbox Code Playgroud)

这个循环没有终止,所以我试着找到使用的记录数,rs.getFetchSize()并返回一个值10.我想知道这是否是找出ResultSet中记录数的正确方法,如果计数为10,为什么它会进入无限循环.请提出你的意见.

java jdbc resultset

5
推荐指数
2
解决办法
2万
查看次数

如何运行Resultset.next()两次?

我有这个方法来获取一串行并打印它们.

另外,我要做while(Resultset.next())两次.第一个是获取行数,第二个是打印字符串.但是当方法第一次运行时Resultset.next(),方法会跳过第二次Resultset.next().

public static String[] gett() throws ClassNotFoundException, SQLException{

    // this for get conneced to the database .......................

    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr","111"); 
    Statement st = conn.createStatement();
    ResultSet re = st.executeQuery("select location_id from DEPARTMENTS");

    // Ok , now i have the ResultSet ...

    // the num_row it's counter to get number of rows
    int num_row = 0;

    // this Arrar to store String values
    String[] n = new String[num_row];

    // this is the first …
Run Code Online (Sandbox Code Playgroud)

java sql oracle jdbc resultset

3
推荐指数
1
解决办法
5328
查看次数

标签 统计

java ×3

jdbc ×3

resultset ×2

oracle ×1

sql ×1