1. 程式人生 > >Mybatis批量更新報錯com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

Mybatis批量更新報錯com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

批量更新資料,非常簡單的一段程式碼,硬是報錯,插入的資料也能顯示出來

List<User> userlist = new ArrayList<User>();
		userlist.add(new User(1, "qq", "123132", "eee"));
		userlist.add(new User(2, "3333", "123132", "rrrr"));

		int i = usermapper.updateData(userlist);
<!-- 批量更新 -->
	<update id="updateData" parameterType="list">
		<foreach collection="list" item="item" separator=";">
			update useres
			<set>
				uname=#{item.uname},pwd=#{item.pwd},realname=#{item.realname}
			</set>
			where
			id=#{item.id}
		</foreach>
	</update>

[main] 2018/09/01 15:55:59  DEBUG (BaseJdbcLogger.java:132) - ooo Using Connection 
[main] 2018/09/01 15:55:59  DEBUG (BaseJdbcLogger.java:132) - ==>  Preparing: update useres SET uname=?,pwd=?,realname=? where id=? ; update useres SET uname=?,pwd=?,realname=? where id=? 
[main] 2018/09/01 15:55:59  DEBUG (BaseJdbcLogger.java:132) - ==> Parameters: qq(String), 123132(String), eee(String), 
### The error may involve com.bjsxt.user.entity.UserMapper.updateData-Inline
### The error occurred while setting parameters
### SQL: update useres     SET uname=?,pwd=?,realname=?     where    id=?    ;     update useres     SET uname=?,pwd=?,realname=?     where    id=?
### 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 useres
             SET uname='3333',pwd='123132',realname='rrrr' 
            where
            id=' at line 6
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:150)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:49)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
    at com.sun.proxy.$Proxy0.updateData(Unknown Source)
    at com.bjsxt.user.test.TestMapper.main(TestMapper.java:41)
Caused by: 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 useres
             SET uname='3333',pwd='123132',realname='rrrr' 
            where
            id=' at line 6
   

最終,解決了問題如果連續執行多條sql語句 需要在url的後面 補充一個allowMultiQueries=true 即可
 

<property name="url" value="jdbc:mysql://localhost:3306/test?allowMultiQueries=true" />

[main] 2018/09/01 16:04:23  DEBUG (BaseJdbcLogger.java:132) - ooo Using Connection [[email protected]]
[main] 2018/09/01 16:04:23  DEBUG (BaseJdbcLogger.java:132) - ==>  Preparing: update useres SET uname=?,pwd=?,realname=? where id=? ; update useres SET uname=?,pwd=?,realname=? where id=? 
[main] 2018/09/01 16:04:23  DEBUG (BaseJdbcLogger.java:132) - ==> Parameters: qq(String), 123132(String), eee(String), 1(Integer), 3333(String), 123132(String), rrrr(String), 2(Integer)
[main] 2018/09/01 16:04:23  DEBUG (BaseJdbcLogger.java:132) - <==    Updates: 1
1
[main] 2018/09/01 16:04:23  DEBUG (JdbcTransaction.java:66) - Committing JDBC Connection [[email protected]]
[main] 2018/09/01 16:04:23  DEBUG (JdbcTransaction.java:117) - Resetting autocommit to true on JDBC Connection [[email protected]]
[main] 2018/09/01 16:04:23  DEBUG (JdbcTransaction.java:85) - Closing JDBC Connection [[email protected]]
[main] 2018/09/01 16:04:23  DEBUG (PooledDataSource.java:332) - Returned connection 1558712965 to pool.
 

相關推薦

Mybatis批量更新com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

批量更新資料,非常簡單的一段程式碼,硬是報錯,插入的資料也能顯示出來 List<User> userlist = new ArrayList<User>(); userlist.add(new User(1, "qq", "123132", "e

在資料庫連線名跟密碼還有資料庫名字也正確的時候com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied fo

56385 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] WARN  com.mchange.v2.resourcepool.BasicResourcePool  – [email

hibernate儲存實體類com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException

java.lang.RuntimeException: org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; SQL [insert into SFORM_FTL (CREAT

將windows上面的項目拷貝到Linux環境下不能夠找到對應的表com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'puyang.ServiceType' doesn't exist

exce 服務 inux 區分 大小 blog alt logs 就會 將一模一樣的項目從win遷移到到linux上報錯: 一開始還是以為是linux不能識別hql語句,查找資料發現是因為Liunx服務器上mysql是區分大小寫的,而本地是不區分的如:代碼是這樣寫的@En

java.lang.Exception: 資源處理失敗,失敗原因:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column '?????‰' in 'where clause'

exception 替換 div name jdbc unknown syn lan -s 1:Unknown column ‘?????‰‘ in ‘where clause‘,這個問題,百度一搜,挺多的,但是貌似好像沒有解決我的問題。貼一下我是如何拼接sq

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column

例如 stmt string 數據庫操作 mys 異常 數據庫 exec execute com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column …… 出現這個異常的很大可能性是 數

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; che

出現此種錯誤,我暫時遇到了兩次。 1 我的欄位的名稱和資料庫的關鍵字重合。 上圖中的desc是預設降序排列的意思。 2 第二次出現的異常是我在重構程式碼階段遇到的一個bug.不過我暫時不能理解,雖然解決了錯誤。 刪除操作的程式碼如下: public void delet

[jnhs]hibernate只能建立一張/表不建立表com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'kaihu.t_client_info' doesn't exist和org.hibern

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'kaihu.t_client_info' doesn't exist  有兩個model,使用第一個dao的時候可以自動建立表 但是使用第二個model的時候不能

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException最全解決

org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax;

SQL: insert into order      ( user_id,                       order_id,  

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 解決方案

當我將資料庫放到伺服器遠端訪問的時候出現了Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user 'sq_shiyezhe'@'2

com mysql jdbc exceptions jdbc4 MySQLSyntaxErrorException U

mys delay text solved task reflect prop reads trac 1、錯誤描述 2014-7-12 21:06:05 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource get

java項目連接jdbccom.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server

image mysq reat jar包 tor ima 新版 ransient java項目 java項目連接jdbc報錯:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Coul

資料庫com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'ua' at row 1

記一次報錯記錄,成長路上的點滴 明明使用瀏覽器或者微信開發工具除錯介面沒有問題,但是在真機測試時候就出問題了。(((¬_¬)) 500伺服器內部錯誤,要死的節奏啊 登陸tomcat伺服器 使用命令tail -f /usr/local/tomcat/logs/catalina.out 檢視實時日誌輸出

mybatis批量更新 MySQLSyntaxErrorException: You have an error in your SQL syntax; check the near 'UPDAT

問題: Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corre

MyBatis批量更新org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.bindin

需求描述:今天在專案中寫了一個批量更新的操作,dao層使用的是MyBatis框架。 錯誤資訊:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.bi

【專案com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '5' for key 'PRIMARY' at sun.reflect.NativeCo

執行Class.forName com.mysql.jdbc.Driverjava.lang.NullPointerException

使用eclipse打成可執行jar包,執行提示“jar中沒有主清單屬性” 檢視MANIFEST.MF檔案,檢視沒有Main-Class 屬性值,新增如下。 Manifest-Version: 1.0 Rsrc-Class-Path: ./ postgresq

mybatis批量更新問題解決

最近在做一個會員營銷專案,其中有業務涉及到批量update問題,我用mybatic foreach實現批量update,但sql一直沒問題,但是偏偏報以下奇葩問題: org.springframework.jdbc.BadSqlGrammarException: ###

mybatis異常 bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorE

<select id="queryPastLimit" resultMap="BaseResultMap">select <include refid="Base_Column_List"/>from  hui_app_lottery_past where lotterytype =