2012-12-26 33 views
-2

您好我需要在我的本地數據庫更新新的人,而添加一個新的人它顯示了以下錯誤:語法錯誤,同時更新數據庫

Failure 1 (near "Build": syntax error) on 0x29abd0 when preparing 'update event_details set total_checkin=12, checkin=7, yet_to_check=5 where event_name=Final Build Test'. 

我原來的Java代碼:

strQuery = "update event_details set total_checkin="+ strTotalMembers + ", checkin="+ strTotalCheckIns + ", yet_to_check="+ strYetToChecks + " where event_name=" + strTitle; 

mySqlite.executeQuery(strQuery); 

所有表格列拼寫正確。但是我知道爲什麼會出現這個錯誤。請告訴我們來解決這個問題。

+0

在單引號 – aland

回答

1

試試這個:

strQuery = "update event_details set total_checkin='"+ strTotalMembers + "', checkin='"+ strTotalCheckIns + "', yet_to_check='" + strYetToChecks + "' where event_name='"+ strTitle +"'"; 

因爲你需要通過在 '' 所有的字符串。

+0

由於只是包裝「最終構建測試」。工作正常。 – Dhamodharan

1

您在字符串值(s)周圍缺少single-quotes。你應該使用主機變量來處理這個問題。

0

您不應該自己手動構建您的查詢。這是有風險的,並打開你的SQL注入代碼(谷歌)。這就是爲什麼你應該總是使用某種API來支持prepareStatement方法,這些方法會接受佔位符(通常是qestionmark)和分離變量的查詢。該方法應該爲你填充的地方持有人需要照顧報價,字符編碼等 只是例子:http://php.net/manual/en/pdo.prepared-statements.php

我是aure你會發現更多在谷歌。

希望它有助於