1
我已經使用JDBC來從表中刪除的記錄中刪除命令,而eexcuting一樣,我得到一個錯誤,因爲我有如下圖所示:得到錯誤在MySQL通過Java代碼
java.sql.SQLException: Before start of result set
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:841)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2674)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2815)
at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:236)
at net.ordernet.vd.lookupTable.UpdateLookupTable.deleteLookupTableRecords(UpdateLookupTable.java:118)
at net.ordernet.vd.soap.UpdateLookupTableTool.deleteLookupTableRecords(UpdateLookupTableTool.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
我的代碼如下所示: 1)兩個字符串被用來指定查詢 2)連接對象用於準備語句 3)在'int'變量中檢查更新查詢的結果 4)我還沒有使用結果集,得到結果集例外,雖然...!
try
{
String queryDeleteLookupTableRecords = "delete from LookupTableRecords where tableId = ?";
String queryDeleteLookupTableRows = "delete from LookupTableRows where tableId = ?";
PreparedStatement psDeleteLookupTableRecords = oConnection.prepareStatement(queryDeleteLookupTableRecords);
PreparedStatement psDeleteLookupTableRows = oConnection.prepareStatement(queryDeleteLookupTableRows);
psDeleteLookupTableRecords.setInt(1, oLookupTable.getID());
psDeleteLookupTableRows.setInt(1, oLookupTable.getID());
int result = psDeleteLookupTableRecords.executeUpdate();
int result2 = psDeleteLookupTableRows.executeUpdate();
if(result > 0 && result2 > 0)
{
iReturnValue = 1;
}
psDeleteLookupTableRecords.close();
psDeleteLookupTableRows.close();
}
catch (SQLException oSqlException)
{
Log.print(oSqlException);
}
之前,您在某處有
resultSet.getInt(..)
棧跟蹤和代碼段似乎沒有任何關聯。你可以發佈方法'UpdateLookupTable.deleteLookupTableRecords()'的代碼嗎?你在'ResultSet'上調用'getInt()',看起來你在這之前沒有調用'rs.next()'。 –如果您能確定發生異常的位置,這將有所幫助。並在問題中註釋代碼以向我們展示。 – Johan
@PhilippReichart,'delete'語句不返回結果集。而且代碼是''setint' **不是GETINT – Johan