int i=0;
while(rs.next())
{
i++;
}
...
<%=i%>

解决方案 »

  1.   

    rs.last();
    int count=rs.getRow();
      

  2.   

    没有直接的方法?
    类似rs.getrow()
      

  3.   

    ResultSet rs=.........
    rs.last();
    int sum=rs.getRow();
      

  4.   

    select count(*) from tb where ....
    or 
    int sum=rs.getRow();
      

  5.   

    public int getsqlnum(String sql)
        {
            int i = 0;
            //Vector v = new Vector();
            ResultSet rs1 = null;
            try
            {
                sql = sql.trim();
                if (myconn !=null)
                   myconn.close();
                myconn = DriverManager.getConnection(sConnStr, UseName, PassWord);
                Statement statement = myconn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                rs1 = statement.executeQuery(sql);
                rs1.last();
                i = rs1.getRow();
                //while(rs1.next())
                //{ i++; }
                rs1.close();
                rs1 = null;
                myconn.close();
                myconn = null;
                
            }
            catch(Exception e)
            {
                System.out.print("getsqlnum error" +e.getMessage());
                //rs1 = null;
                //return 0;
            }
            return i;
        }
      

  6.   

    select count(*) from tablename
      

  7.   

    我是这样写的!就一二句搞定的!不知前头有人这样写了没!??呵呵~rs2=sqlStmt.executeQuery(sql2);
    if(rs2.next())
    {
    int n=rs2.getRow();

    do
    n就是记录个数了!
      

  8.   

    除非數據庫提供特別優化,
    否則,一般使用:
    select count(1) from tablename where ....
      

  9.   

    int i=0;
    while(rs.next())
    {
    i++;
    }
    ...
    <%=i%>
      

  10.   

    同意Leemaasn(呆鸟一号)的方法!
      

  11.   

    用select count(*) from tablename
    方法得到的只是一个值吗?
      

  12.   

    用select count(*) as count from tablename
    加上 as count可以用getString("count")得到不然得用getString(1)获取
      

  13.   

    to:batt
    这样写对不对?
    String sql="select count(*) as count from table";
    ......
    ps = con.prepareStatement(sql);
    rs = ps.executeQuery();
    String sum=rs.getString("count");
      

  14.   

    这样写才对!!String sql="select count(*) as count from table";
    ps = con.prepareStatement();
    rs = ps.executeQuery(sql);
    String sum=rs.getString("count");
      

  15.   

    TO Leemaasn(呆鸟一号) :还是老哥厉害呵呵~~
      

  16.   

    String sum=rs.getString("count");int sum=rs.getInt("count");道理一样吧,只是类型不一样罢了