java sql 异常求解答
public boolean DeleteId(int IDvalue,String typename){
try{
pst = Connect.dbConn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
//pst.executeQuery("insert into UnuseIdInfo (typename,unuseid) values('"+typename+"',"+IDvalue+")");//IdFormatInfo
ResultSet rsd = pst.executeQuery("insert UnuseIdInfo(typename,unuseid)values('"+"student"+"',0)");}catch(SQLException e){
throw new RuntimeException(e);
}finally{
try{
pst.close();
pst = null;
}catch(SQLException e){
throw new RuntimeException(e);
}
}
return true;
}
执行成功,在sql中增加了相应的记录,但是,抛出异常,
Exception in thread "main" java.lang.RuntimeException: com.microsoft.sqlserver.jdbc.SQLServerException: 该语句没有返回结果集。
at Server.IdServer.DeleteId(IdServer.java:213)
at Client.Request.RecycleID(Request.java:96)
at Test.Test.main(Test.java:20)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 该语句没有返回结果集。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:783)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:676)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:611)
at Server.IdServer.DeleteId(IdServer.java:210)
... 2 more
[解决办法]
executeQuery--->executeUpdate
[解决办法]
executeQuery是查询,要调用executeUpdate