public static int getResultSetCount(ResultSet rs)
{
try
{
if(rs.next())
{
rs.last();
int i = rs.getRow();
rs.beforeFirst();
return i;
}
else
return 0;
}catch(SQLException e)
{
return 0;
}
}
{
try
{
if(rs.next())
{
rs.last();
int i = rs.getRow();
rs.beforeFirst();
return i;
}
else
return 0;
}catch(SQLException e)
{
return 0;
}
}
{
try
{
if(rs.next())
{
rs.last(); //将指针移动到最后一条记录
int i = rs.getRow(); //取得当前的位置 ! 即记录总数
rs.beforeFirst(); //将指针移动到最开始的位置,即0
return i;
}
else
return 0;
}catch(SQLException e)
{
return 0;
}
}
<%
int i = 类名.getResultSetCount(rs); //static方法。所以不用new.
%>
resultSet.next();
int rowcount=resultSet.getInt(1);
(注: class中指定 DBmanager 路径)
<%
ResultSet rs ;
int iCount = 0 ;
iCount = DBmanager.getResultSetCount(rs) ;%>
while(rs.next()){
......
countRows++;
......
}
//return countRows; /*****你可以选择返回或者用getter取出此数******/如果只要记录条数,推荐用SQL的方式/select count(*)....