用ODBC连接SQLServer2000,用preparedStatement查询一个数据库中有的记录,怎么出现上面的异常呢?有什么解决方法吗?这个问题捆扰了我好几天了...Class.forName(driver);
_connection = DriverManager.getConnection(source);
_prepSetStatus1 = _connection.prepareStatement("SELECT count(*) as qty FROM tblWorkload WHERE URL = ?;");
_prepSetStatus2 = _connection.prepareStatement("INSERT INTO tblWorkload(URL,Status) VALUES (?,?);");
_prepSetStatus3 = _connection.prepareStatement("UPDATE tblWorkload SET  Status = ? WHERE URL = ?;");

函数如下:
synchronized protected void setStatus(String url,char status)
{
url = url.trim();
ResultSet rs = null;
try
{
//first see if one exists
_prepSetStatus1.setString(1,url);
System.out.println("Ready to query the number of :"+url);
rs = _prepSetStatus1.executeQuery();
rs.next();
int count = rs.getInt("qty");
if(count < 1)
{
//Create one
_prepSetStatus2.setString(1,url);
_prepSetStatus2.setString(2,(new Character(status)).toString());
_prepSetStatus2.executeUpdate();
}
else
{
_prepSetStatus3.setString(1,(new Character(status)).toString());
_prepSetStatus3.setString(2,url);
_prepSetStatus3.executeUpdate();
}
}catch(SQLException e)
{
Log.logException("SQL Error:",e);
System.out.println("Fail to change his status:"+url+":"+e);
}finally
{
try
{
if(rs!= null)
{
rs.close();

}
}catch(Exception e){}
}
}

解决方案 »

  1.   

    ODBC 支持的特性会少一些,难免有些问题.
      

  2.   

    int count = rs.getInt("qty");改成int count = rs.getInt(1);
    程序我看过了,没有什么问题,不知道你的错误是什么?
      

  3.   

    因为都是一个Connection,因为没有close导致占线,不在使用的对象一定要马上close释放联结,避免出现这种情况
      

  4.   

    btb368() 出错的行为:rs = _prepSetStatus1.executeQuery();第一次执行没问题,而且如果count == 0时也没问题。所以不知道怎么回事,郁闷。。,
      

  5.   

    MagicianLiu(魔术师·刘) :数据库连接池,怎么用啊? 不好意思,没怎么接触过数据库 ^_^#