關於“The error occurred while applying a parameter map.”的問題,
今天我也寫一點,那就是找準改錯的方向,不然小錯費大事
我今天的錯誤:如下
更新userMain失敗org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation;
bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/hunai/pojo/sqlmap/umUserMain-sqlmap.xml.
--- The error occurred while applying a parameter map.
--- Check the UserMain.updateUmPwd-InlineParameterMap.
--- Check the statement (update failed).
--- Cause: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where mum.UM_UserID=37' at line 1
出錯地方:
<update id="UserMain.updateUmPwd">
<![CDATA[
update
mi_user_main mum
set
mum.UM_Pwd=#1#,
where
mum.UM_UserID=#2#
]]>
</update>
遇到“The error occurred while applying a parameter map”這種錯誤,首先想到的是字段對應的錯誤,
但是像這種低價錯誤,iBATIS會很明確的指出出錯的地方的。
這種想法應該排除的。
不過上面很明顯說是bad SQL grammar ;
那就把這個語句粘貼到數據庫做個測試,不能去瞎找,我今天就犯了很大的錯誤,
沒有尋本求源,總感覺sql語法不會有問題,就去瞎忙活,看下傳參是否出錯呀,之類的,整了老半天,
最後實在想不出是什麼地方出錯,就到數據庫測試語句,果然,根本性的原因還是sql語句,多了一個逗號
set
mum.UM_Pwd=#1#,
唉,真是慚愧呀,這麼低級的錯誤本不該發生,可是,發生了,會讓人很苦惱。
所以,方向與方法非常重要,少走彎路。