org.springframework.jdbc.BadSqlGrammarException:
### Error updating database. Cause: java.sql.SQLSyntaxErrorException: 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 user SET password=’24d39f8297d2e59ee7afa93d131b8a45′,email=’0e1e75c4ebb11’ at line 3
### The error may exist in file [D:\git\encryption\target\classes\mapper\UserMapper.xml]
### The error may involve com.demo.encryption.mapper.UserMapper.updateBatchUserById-Inline
### The error occurred while setting parameters
### SQL: UPDATE user SET password=?,email=? WHERE id=?; UPDATE user SET password=?,email=? WHERE id=?; UPDATE user SET password=?,email=? WHERE id=?; UPDATE user SET password=?,email=? WHERE id=?;
### Cause: java.sql.SQLSyntaxErrorException: 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 user SET password=’24d39f8297d2e59ee7afa93d131b8a45′,email=’0e1e75c4ebb11’ at line 3
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: 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 user SET password=’24d39f8297d2e59ee7afa93d131b8a45′,email=’0e1e75c4ebb11’ at line 3
JDBC API 是针对每个语句的,而您的代码一次执行两个语句。一般来说,这是行不通的。对于 MySQL Connector/J,您可以通过将连接属性allowMultiQueries
设置为 true 来将其配置为接受多个语句。
# 数据源
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true&allowMultiQueries=true
username: root
password: 123456
😁