1. 程式人生 > >jdbc.url,請記得帶上我,allowMultiQueries=true

jdbc.url,請記得帶上我,allowMultiQueries=true

今天被一個MySQL異常糾纏了許久,大概是忘帶東西,但是它非得讓我帶,不帶就不讓我走...,到底是什麼東西呢,請接著放下看:
org.springframework.jdbc.BadSqlGrammarException: 
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.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 'UPDATE t_dream_product p,t_dream_product_temp t SET p.product_enabled = 0' at line 6 ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: UPDATE t_dream_product p,t_dream_product_temp t SET t.status_value = p.status_value WHERE t.pk_id = p.pk_id and
t.status_value != p.status_value; UPDATE t_dream_product p,t_dream_product_temp t SET p.product_enabled = 0 WHERE t.pk_id = p.pk_id AND t.keyword = '0' ; UPDATE t_dream_product_temp t, t_dream_product p SET t.keyword = 0,t.product_enabled = 0 WHERE t.pk_id = p.pk_id AND
p.product_enabled = 0 ; delete from t_dream_product_cate where EXISTS (select 1 from t_dream_product p where p.pk_id = t_dream_product_cate.product_id and p.product_enabled = 0); ### Cause: com.mysql.jdbc.exceptions.jdbc4.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 'UPDATE t_dream_product p,t_dream_product_temp t SET p.product_enabled = 0' at line 6; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.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 'UPDATE t_dream_product p,t_dream_product_temp t SET p.product_enabled = 0' at line 6 at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371) at com.sun.proxy.$Proxy10.update(Unknown Source)

以上是異常的提示資訊。

事情經過:在進行更新操作的時候報錯:
     當前環境是資料庫版本:5.7.12、連線驅動版本:mysql-connector-java-5.1.35.jar
     如果是關鍵詞報錯的話,已經將product_enabled 該成enabled、t_enabled之後都不行,
     如果是連線驅動版本的問題,嘗試過5.1.34、5.1.41。
     嘗試直接將SQL語句放入Navicat執行,結果正常
     嘗試修改欄位名稱,結果報錯
     嘗試單獨執行報錯的語句,結果正常的。
     嘗試將update下的任意兩句sql放一起執行,結果報錯,
得出結論:當前配置不支援多條SQL語句同時執行這種寫法,並不是表的關鍵字與資料庫衝突,但是這種寫法應該是支援的,檢查資料庫連線配置才發現jdbc.url上沒有配置allowMultiQueries=true引數。配置上後,問題迎刃而解。明明記得自己是配置過的,但是現實狠狠地扇了我一個響亮的大嘴巴子。