用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){}
}
}
_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){}
}
}
程序我看过了,没有什么问题,不知道你的错误是什么?