日期:2014-05-18  浏览次数:20472 次

取得记录总数的错误?
public   String   getPageCount()
{
    String   pc= " ";
    try
    {
        String   sql   =   "SELECT   COUNT(*)   FROM   RMS.dbo.prd_pic_tbl_pic ";
        conn   =   DatabaseDao.getConn();
        stmt   =   conn.createStatement();
        rs   =   stmt.executeQuery(sql);
        pc=rs.getString(0);
    }   catch   (Exception   e)
    {    
        e.printStackTrace();
    }
        return   pc;
}

================================错误提示
java.sql.SQLException:   [Microsoft][SQLServer   2000   Driver   for   JDBC]Invalid   operation   for   the   current   cursor   position.
at   com.microsoft.jdbc.base.BaseExceptions.createException(Unknown   Source)
at   com.microsoft.jdbc.base.BaseExceptions.getException(Unknown   Source)
at   com.microsoft.jdbc.base.BaseResultSet.validateCursorPosition(Unknown   Source)
at   com.microsoft.jdbc.base.BaseResultSet.getString(Unknown   Source)

好象是查询语句的问题,那里写错了?连接是正常的
第一次用SQL   Server,请高手帮下忙

------解决方案--------------------
把连接字符串贴出来看看
------解决方案--------------------
public String getPageCount()
{
String pc= " ";
try
{
//String sql = "SELECT COUNT(*) FROM RMS.dbo.prd_pic_tbl_pic ";
改成String sql = "SELECT COUNT(*) as exist FROM RMS.dbo.prd_pic_tbl_pic ";
conn = DatabaseDao.getConn();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
pc=rs.getString( "exist ");
} catch (Exception e)
{
e.printStackTrace();
}
return pc;
}

--还有楼主应该加个finally关闭数据库连接 :)

------解决方案--------------------
java看不太懂。
------解决方案--------------------
pc=rs.getString(0);

String ???
好象应该是个数字吧????
JAVA 我也不懂