select count(ta.code) from table1 ta,table2 tb
where ta.code=tb.code

解决方案 »

  1.   

    rs.last();
    int total=rs.getRow();
    total 就是记录总数
      

  2.   

    rs=stmt.executeQuery("select count(*) as num from table");
    int p=rs.getInt("num");
    p就是总数
      

  3.   

    sql=select count(*) from table1 ta,table2 tb
    RS.next();
    intRowCount=RS.getInt(1);
      

  4.   

    Statement st =conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = st.executeQuery("select * from table1");
    rs.last();
    int count = rs.getRow();
    rs.beforeFirst();
    while(rs.next())
    {
    ...
    }
      

  5.   

    方法一:
    Statement St = Conndefinedres.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    ResultSet Rs = St.executeQuery(sql);
    Rs.last(); 
    int Rs_count = Rs.getRow();
    Rs.first();//重新回到第一个记录;
    方法二:
    Statement St = Conndefinedres.createStatement();
    ResultSet Rs = St.executeQuery(sql);
    Rs.next();
    int Rs_total=0;
    for (Rs_total = 1; Rs.next(); Rs_total++);
      // reset the cursor to the beginning
    Rs.close();
    Rs = St.executeQuery(sql);
    Rs.next();
      

  6.   

    這個問題要具體分析.
    如果你的查詢你可以一個語句高定,那麼像上面幾位兄弟的方法就可以高定.
    如果你的查詢很複雜,你可以先建視圖(View)來高定
      

  7.   

    con = DbConnectionManager.getConnection();
    pstmt = con.prepareStatement(SELECT count(*) FROM user_info);
    ResultSet rs = pstmt.executeQuery();
                if (rs.next()) {
                    count = rs.getInt(1);
                }
    这样就行了!
      

  8.   

    count(*)是速度最快的,如果采用移动游标的办法的话,如果数据量大的话会很慢的建议使用count(*)
      

  9.   

    你就用相同的条件查一次,不过返回记录数就可以了。
    int i = 0;
    while (rst.next()){
    i++;
    rst.next;
    }
      

  10.   

    select count(field1),* from table1