2012-02-23 159 views
0

我有一個sql更新語句,但我不明白爲什麼它不會更新我的記錄,它只是什麼都不做,語法有什麼問題嗎?SQL更新語句不改變記錄

private static final String strUpdatePerson = 
     "UPDATE APP.PERSON " + 
     "SET FIRSTNAME = ?, " + 
     " LASTNAME = ?, " + 
     " ADDRESS = ?, " + 
     " PHONE = ?, " + 
     " EMAIL = ?, " + 
     " INFO = ? " + 
     "WHERE ID = ?"; 

這很混亂,因爲沒有給出錯誤,它執行更新但在數據庫中沒有任何變化。

編輯:

這裏是正在執行的查詢:

stmtUpdateExistingRecord = dbConnection.prepareStatement(strUpdateCustomer); 


    stmtUpdateExistingRecord.clearParameters(); 
     stmtUpdateExistingRecord.setString(1, record.firstName.toUpperCase()); 
     stmtUpdateExistingRecord.setString(2, record.lastName.toUpperCase()); 
     stmtUpdateExistingRecord.setString(3, record.Address); 
     stmtUpdateExistingRecord.setString(4, record.phoneNumber); 
     stmtUpdateExistingRecord.setString(5, record.email); 
     stmtUpdateExistingRecord.setString(6, record.info); 
     stmtUpdateExistingRecord.setInt(7, record.getID()); 
     stmtUpdateExistingRecord.executeUpdate(); 
+1

你如何使用該聲明?請爲社區提供使用該聲明的代碼的和平。 – 2012-02-23 19:17:17

+2

也許事務回滾而不是承諾。向我們展示代碼。 – 2012-02-23 19:18:48

+0

您確定您綁定了正確的ID值(即它是否存在於數據庫中)? – GriffeyDog 2012-02-23 19:42:06

回答

2

你應該調用dbConnection.setAutoCommit(true);executeUpdate()dbConnection.commit();之前executeUpdate()

如果dbConnection.getAutoCommit()返回true,則您遇到不同的錯誤。你確定它不扔Exception

+0

對不起,我把這些代碼拼湊在一起。因爲其他查詢正常工作,所以對於dbconnection一切正常。是的,沒有任何例外,這很奇怪。大多數情況下,它更新,什麼都不做,但有時它會給出一個SQL超時錯誤 – Ross 2012-02-23 19:31:21

+0

聽起來像你的數據庫可能會奇怪地行事。你是否嘗試直接使用實用程序在數據庫上運行查詢? – 2012-02-23 19:44:24