我正在优化一些 SQL 查询。我已经编写了它们来使用批处理。集成测试运行良好,一切都很愉快。但是后来我了解到除非启用 rewriteBatchedStatements,否则 MySQL 不会提高性能。
所以我修改了我的连接字符串以包含 rewriteBatchedStatement,但我开始收到 MySQLSytaxErrorException。当我从连接字符串中删除 rewriteBatchedStatement 时,异常消失了。
查询语句: INSERT INTO rawdata.scales (ID, NAME) VALUES (?, ?)
例外:
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 ';INSERT INTO rawdata.scales` at line 1
奇怪的是,这只发生在我设置的测试中运行的第一个 SQL 语句上。所有其他人都运行良好。
为什么启用此功能会在我的 SQL 前面添加一个分号?
小智 5
连接器/J 5.1.40 到并包括至少 5.1.43 中存在一个已知问题,该问题导致在启用 rewriteBatchedStatement 时在插入时抛出 MySQLSytaxErrorException。
见https://bugs.mysql.com/bug.php?id=84813
我已经能够在带有尾随分号的语句中重现这一点,例如
INSERT INTO rawdata.scales (ID, NAME) VALUES (?, ?);
Run Code Online (Sandbox Code Playgroud)
删除尾随分号可以解决我的问题。