项目实际开发中,使用到了MySQL批量插入的语法,在MySQL中执行成功后,移植到项目时发生了问题,语句如下:
REPLACE INTO table1(
id,
works_fusion_id,
statistics_date,
chapter_number,
new_chapter,
works_hot,
works_like_number,
works_read_number,
works_comment_number,
works_collection_number
)
SELECT
(SELECT UPPER(REPLACE(result.id, '-', ''))) id,
result.works_fusion_id,
STR_TO_DATE(IFNULL(result.statistics_date,'1990-01-01'),'%Y-%m-%d') statistics_date,
IFNULL(result.chapter_number,0) chapter_number,
IFNULL(result.new_chapter,'无数据') new_chapter,
IFNULL(result.works_hot,0) works_hot,
IFNULL(result.works_like_number,0) works_like_number,
IFNULL(result.works_read_number,0) works_read_number,
IFNULL(result.works_comment_number,0) works_comment_number,
IFNULL(result.works_collection_number,0) works_collection_number
FROM(
SELECT
UUID() id,
swf.id as works_fusion_id,
DATE_FORMAT(sdr.update_time,'%Y-%m-%d') statistics_date,
COUNT(DISTINCTROW sccount.id) chapter_number,
sci.title new_chapter,
sum(DISTINCT sdr.works_hot) works_hot,
sum(DISTINCT sdr.works_read_number) works_read_number,
sum(DISTINCT sdr.works_like_number) works_like_number,
sum(DISTINCT sdr.works_comment_number) works_comment_number,
sum(DISTINCT sdr.works_collection_number) works_collection_number
FROM table2 swf
INNER JOIN table3 sw ON sw.works_fusion_id=swf.id
GROUP BY swf.id
)result
项目中执行SQL报错内容:
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@10d97b64] was not registered for synchronization because synchronization is not active
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3bbdf835] will not be managed by Spring
==> Preparing: REPLACE INTO sqa_day_data_statistics( id, works_fusion_id, statistics_date, chapter_number, new_chapter, works_hot, works_like_number, works_read_number, works_comment_number, works_collection_number ) SELECT (SELECT UPPER(REPLACE(result.id, '-', ''))) id, result.works_fusion_id, STR_TO_DATE(IFNULL(result.statistics_date,'1990-01-01'),'%Y-%m-%d') statistics_date, IFNULL(result.chapter_number,0) chapter_number, IFNULL(result.new_chapter,'无数据') new_chapter, IFNULL(result.works_hot,0) works_hot, IFNULL(result.works_like_number,0) works_like_number, IFNULL(result.works_read_number,0) works_read_number, IFNULL(result.works_comment_number,0) works_comment_number, IFNULL(result.works_collection_number,0) works_collection_number FROM( SELECT UUID() id, swf.id as works_fusion_id, DATE_FORMAT(sdr.update_time,'%Y-%m-%d') statistics_date, COUNT(DISTINCTROW sccount.id) chapter_number, sci.title new_chapter, sum(DISTINCT sdr.works_hot) works_hot, sum(DISTINCT sdr.works_read_number) works_read_number, sum(DISTINCT sdr.works_like_number) works_like_number, sum(DISTINCT sdr.works_comment_number) works_comment_number, sum(DISTINCT sdr.works_collection_number) works_collection_number FROM sqa_works_fusion swf INNER JOIN sqa_works sw ON sw.works_fusion_id=swf.id INNER JOIN sqa_data_record sdr ON sdr.works_id=sw.id AND sdr.update_time = ( SELECT MAX(update_time) FROM sqa_data_record WHERE works_id = sdr.works_id ) INNER JOIN sqa_chapter_info sci ON sci.works_id=sw.id AND sci.`no`=( SELECT MAX(`no`) FROM sqa_chapter_info WHERE works_id =sci.works_id ) INNER JOIN sqa_chapter_info sccount on sccount.works_id=sw.id GROUP BY swf.id )result
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@10d97b64]
2019-06-10 14:25:24.732 INFO 2240 --- [ main] o.s.b.f.xml.XmlBeanDefinitionReader : Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2019-06-10 14:25:24.758 INFO 2240 --- [ main] o.s.jdbc.support.SQLErrorCodesFactory : SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]
org.springframework.jdbc.UncategorizedSQLException:
### Error updating database. Cause: java.sql.SQLException: sql injection violation, syntax error: syntax error, expect RPAREN, actual IDENTIFIER pos 949, line 29, column 23, token IDENTIFIER sccount : REPLACE INTO sqa_day_data_statistics(
id,
works_fusion_id,
statistics_date,
chapter_number,
new_chapter,
works_hot,
works_like_number,
works_read_number,
works_comment_number,
works_collection_number
)
SELECT
(SELECT UPPER(REPLACE(result.id, '-', ''))) id,
result.works_fusion_id,
STR_TO_DATE(IFNULL(result.statistics_date,'1990-01-01'),'%Y-%m-%d') statistics_date,
IFNULL(result.chapter_number,0) chapter_number,
IFNULL(result.new_chapter,'无数据') new_chapter,
IFNULL(result.works_hot,0) works_hot,
IFNULL(result.works_like_number,0) works_like_number,
IFNULL(result.works_read_number,0) works_read_number,
IFNULL(result.works_comment_number,0) works_comment_number,
IFNULL(result.works_collection_number,0) works_collection_number
FROM(
SELECT
UUID() id,
swf.id as works_fusion_id,
DATE_FORMAT(sdr.update_time,'%Y-%m-%d') statistics_date,
COUNT(DISTINCTROW sccount.id) chapter_number,
sci.title new_chapter,
sum(DISTINCT sdr.works_hot) works_hot,
sum(DISTINCT sdr.works_read_number) works_read_number,
sum(DISTINCT sdr.works_like_number) works_like_number,
sum(DISTINCT sdr.works_comment_number) works_comment_number,
sum(DISTINCT sdr.works_collection_number) works_collection_number
FROM sqa_works_fusion swf
INNER JOIN sqa_works sw ON sw.works_fusion_id=swf.id
INNER JOIN sqa_data_record sdr ON sdr.works_id=sw.id AND sdr.update_time = (
SELECT MAX(update_time) FROM sqa_data_record WHERE works_id = sdr.works_id
)
INNER JOIN sqa_chapter_info sci ON sci.works_id=sw.id AND sci.`no`=(
SELECT MAX(`no`) FROM sqa_chapter_info WHERE works_id =sci.works_id
)
INNER JOIN sqa_chapter_info sccount on sccount.works_id=sw.id
GROUP BY swf.id
)result
### The error may exist in file [/Users/yangxiaohui/HmProject/hm-spss/target/classes/mapper/spss/SqaDayDataStatisticsMapper.xml]
### The error may involve com.hm.spss.mapper.spss.SqaDayDataStatisticsMapper.insertWorksDayDataList
### The error occurred while executing an update
### SQL: REPLACE INTO sqa_day_data_statistics( id, works_fusion_id, statistics_date, chapter_number, new_chapter, works_hot, works_like_number, works_read_number, works_comment_number, works_collection_number ) SELECT (SELECT UPPER(REPLACE(result.id, '-', ''))) id, result.works_fusion_id, STR_TO_DATE(IFNULL(result.statistics_date,'1990-01-01'),'%Y-%m-%d') statistics_date, IFNULL(result.chapter_number,0) chapter_number, IFNULL(result.new_chapter,'无数据') new_chapter, IFNULL(result.works_hot,0) works_hot, IFNULL(result.works_like_number,0) works_like_number, IFNULL(result.works_read_number,0) works_read_number, IFNULL(result.works_comment_number,0) works_comment_number, IFNULL(result.works_collection_number,0) works_collection_number FROM( SELECT UUID() id, swf.id as works_fusion_id, DATE_FORMAT(sdr.update_time,'%Y-%m-%d') statistics_date, COUNT(DISTINCTROW sccount.id) chapter_number, sci.title new_chapter, sum(DISTINCT sdr.works_hot) works_hot, sum(DISTINCT sdr.works_read_number) works_read_number, sum(DISTINCT sdr.works_like_number) works_like_number, sum(DISTINCT sdr.works_comment_number) works_comment_number, sum(DISTINCT sdr.works_collection_number) works_collection_number FROM sqa_works_fusion swf INNER JOIN sqa_works sw ON sw.works_fusion_id=swf.id INNER JOIN sqa_data_record sdr ON sdr.works_id=sw.id AND sdr.update_time = ( SELECT MAX(update_time) FROM sqa_data_record WHERE works_id = sdr.works_id ) INNER JOIN sqa_chapter_info sci ON sci.works_id=sw.id AND sci.`no`=( SELECT MAX(`no`) FROM sqa_chapter_info WHERE works_id =sci.works_id ) INNER JOIN sqa_chapter_info sccount on sccount.works_id=sw.id GROUP BY swf.id )result
### Cause: java.sql.SQLException: sql injection violation, syntax error: syntax error, expect RPAREN, actual IDENTIFIER pos 949, line 29, column 23, token IDENTIFIER sccount : REPLACE INTO sqa_day_data_statistics(
id,
works_fusion_id,
statistics_date,
chapter_number,
new_chapter,
works_hot,
works_like_number,
works_read_number,
works_comment_number,
works_collection_number
)
SELECT
(SELECT UPPER(REPLACE(result.id, '-', ''))) id,
result.works_fusion_id,
STR_TO_DATE(IFNULL(result.statistics_date,'1990-01-01'),'%Y-%m-%d') statistics_date,
IFNULL(result.chapter_number,0) chapter_number,
IFNULL(result.new_chapter,'无数据') new_chapter,
IFNULL(result.works_hot,0) works_hot,
IFNULL(result.works_like_number,0) works_like_number,
IFNULL(result.works_read_number,0) works_read_number,
IFNULL(result.works_comment_number,0) works_comment_number,
IFNULL(result.works_collection_number,0) works_collection_number
FROM(
SELECT
UUID() id,
swf.id as works_fusion_id,
DATE_FORMAT(sdr.update_time,'%Y-%m-%d') statistics_date,
COUNT(DISTINCTROW sccount.id) chapter_number,
sci.title new_chapter,
sum(DISTINCT sdr.works_hot) works_hot,
sum(DISTINCT sdr.works_read_number) works_read_number,
sum(DISTINCT sdr.works_like_number) works_like_number,
sum(DISTINCT sdr.works_comment_number) works_comment_number,
sum(DISTINCT sdr.works_collection_number) works_collection_number
FROM sqa_works_fusion swf
INNER JOIN sqa_works sw ON sw.works_fusion_id=swf.id
INNER JOIN sqa_data_record sdr ON sdr.works_id=sw.id AND sdr.update_time = (
SELECT MAX(update_time) FROM sqa_data_record WHERE works_id = sdr.works_id
)
INNER JOIN sqa_chapter_info sci ON sci.works_id=sw.id AND sci.`no`=(
SELECT MAX(`no`) FROM sqa_chapter_info WHERE works_id =sci.works_id
)
INNER JOIN sqa_chapter_info sccount on sccount.works_id=sw.id
GROUP BY swf.id
)result
; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; sql injection violation, syntax error: syntax error, expect RPAREN, actual IDENTIFIER pos 949, line 29, column 23, token IDENTIFIER sccount : REPLACE INTO sqa_day_data_statistics(
id,
works_fusion_id,
statistics_date,
chapter_number,
new_chapter,
works_hot,
works_like_number,
works_read_number,
works_comment_number,
works_collection_number
)
SELECT
(SELECT UPPER(REPLACE(result.id, '-', ''))) id,
result.works_fusion_id,
STR_TO_DATE(IFNULL(result.statistics_date,'1990-01-01'),'%Y-%m-%d') statistics_date,
IFNULL(result.chapter_number,0) chapter_number,
IFNULL(result.new_chapter,'无数据') new_chapter,
IFNULL(result.works_hot,0) works_hot,
IFNULL(result.works_like_number,0) works_like_number,
IFNULL(result.works_read_number,0) works_read_number,
IFNULL(result.works_comment_number,0) works_comment_number,
IFNULL(result.works_collection_number,0) works_collection_number
FROM(
SELECT
UUID() id,
swf.id as works_fusion_id,
DATE_FORMAT(sdr.update_time,'%Y-%m-%d') statistics_date,
COUNT(DISTINCTROW sccount.id) chapter_number,
sci.title new_chapter,
sum(DISTINCT sdr.works_hot) works_hot,
sum(DISTINCT sdr.works_read_number) works_read_number,
sum(DISTINCT sdr.works_like_number) works_like_number,
sum(DISTINCT sdr.works_comment_number) works_comment_number,
sum(DISTINCT sdr.works_collection_number) works_collection_number
FROM sqa_works_fusion swf
INNER JOIN sqa_works sw ON sw.works_fusion_id=swf.id
INNER JOIN sqa_data_record sdr ON sdr.works_id=sw.id AND sdr.update_time = (
SELECT MAX(update_time) FROM sqa_data_record WHERE works_id = sdr.works_id
)
INNER JOIN sqa_chapter_info sci ON sci.works_id=sw.id AND sci.`no`=(
SELECT MAX(`no`) FROM sqa_chapter_info WHERE works_id =sci.works_id
)
INNER JOIN sqa_chapter_info sccount on sccount.works_id=sw.id
GROUP BY swf.id
)result; nested exception is java.sql.SQLException: sql injection violation, syntax error: syntax error, expect RPAREN, actual IDENTIFIER pos 949, line 29, column 23, token IDENTIFIER sccount : REPLACE INTO sqa_day_data_statistics(
id,
works_fusion_id,
statistics_date,
chapter_number,
new_chapter,
works_hot,
works_like_number,
works_read_number,
works_comment_number,
works_collection_number
)
SELECT
(SELECT UPPER(REPLACE(result.id, '-', ''))) id,
result.works_fusion_id,
STR_TO_DATE(IFNULL(result.statistics_date,'1990-01-01'),'%Y-%m-%d') statistics_date,
IFNULL(result.chapter_number,0) chapter_number,
IFNULL(result.new_chapter,'无数据') new_chapter,
IFNULL(result.works_hot,0) works_hot,
IFNULL(result.works_like_number,0) works_like_number,
IFNULL(result.works_read_number,0) works_read_number,
IFNULL(result.works_comment_number,0) works_comment_number,
IFNULL(result.works_collection_number,0) works_collection_number
FROM(
SELECT
UUID() id,
swf.id as works_fusion_id,
DATE_FORMAT(sdr.update_time,'%Y-%m-%d') statistics_date,
COUNT(DISTINCTROW sccount.id) chapter_number,
sci.title new_chapter,
sum(DISTINCT sdr.works_hot) works_hot,
sum(DISTINCT sdr.works_read_number) works_read_number,
sum(DISTINCT sdr.works_like_number) works_like_number,
sum(DISTINCT sdr.works_comment_number) works_comment_number,
sum(DISTINCT sdr.works_collection_number) works_collection_number
FROM sqa_works_fusion swf
INNER JOIN sqa_works sw ON sw.works_fusion_id=swf.id
INNER JOIN sqa_data_record sdr ON sdr.works_id=sw.id AND sdr.update_time = (
SELECT MAX(update_time) FROM sqa_data_record WHERE works_id = sdr.works_id
)
INNER JOIN sqa_chapter_info sci ON sci.works_id=sw.id AND sci.`no`=(
SELECT MAX(`no`) FROM sqa_chapter_info WHERE works_id =sci.works_id
)
INNER JOIN sqa_chapter_info sccount on sccount.works_id=sw.id
GROUP BY swf.id
)result
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:90)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:82)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:82)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy92.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:64)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:61)
at com.sun.proxy.$Proxy109.insertWorksDayDataList(Unknown Source)
at com.hm.spss.RlTemplateApplicationTests.testsql(RlTemplateApplicationTests.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.sql.SQLException: sql injection violation, syntax error: syntax error, expect RPAREN, actual IDENTIFIER pos 949, line 29, column 23, token IDENTIFIER sccount : REPLACE INTO sqa_day_data_statistics(
id,
works_fusion_id,
statistics_date,
chapter_number,
new_chapter,
works_hot,
works_like_number,
works_read_number,
works_comment_number,
works_collection_number
)
SELECT
(SELECT UPPER(REPLACE(result.id, '-', ''))) id,
result.works_fusion_id,
STR_TO_DATE(IFNULL(result.statistics_date,'1990-01-01'),'%Y-%m-%d') statistics_date,
IFNULL(result.chapter_number,0) chapter_number,
IFNULL(result.new_chapter,'无数据') new_chapter,
IFNULL(result.works_hot,0) works_hot,
IFNULL(result.works_like_number,0) works_like_number,
IFNULL(result.works_read_number,0) works_read_number,
IFNULL(result.works_comment_number,0) works_comment_number,
IFNULL(result.works_collection_number,0) works_collection_number
FROM(
SELECT
UUID() id,
swf.id as works_fusion_id,
DATE_FORMAT(sdr.update_time,'%Y-%m-%d') statistics_date,
COUNT(DISTINCTROW sccount.id) chapter_number,
sci.title new_chapter,
sum(DISTINCT sdr.works_hot) works_hot,
sum(DISTINCT sdr.works_read_number) works_read_number,
sum(DISTINCT sdr.works_like_number) works_like_number,
sum(DISTINCT sdr.works_comment_number) works_comment_number,
sum(DISTINCT sdr.works_collection_number) works_collection_number
FROM sqa_works_fusion swf
INNER JOIN sqa_works sw ON sw.works_fusion_id=swf.id
INNER JOIN sqa_data_record sdr ON sdr.works_id=sw.id AND sdr.update_time = (
SELECT MAX(update_time) FROM sqa_data_record WHERE works_id = sdr.works_id
)
INNER JOIN sqa_chapter_info sci ON sci.works_id=sw.id AND sci.`no`=(
SELECT MAX(`no`) FROM sqa_chapter_info WHERE works_id =sci.works_id
)
INNER JOIN sqa_chapter_info sccount on sccount.works_id=sw.id
GROUP BY swf.id
)result
at com.alibaba.druid.wall.WallFilter.checkInternal(WallFilter.java:806)
at com.alibaba.druid.wall.WallFilter.connection_prepareStatement(WallFilter.java:259)
at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:568)
at com.alibaba.druid.filter.FilterAdapter.connection_prepareStatement(FilterAdapter.java:930)
at com.alibaba.druid.filter.FilterEventAdapter.connection_prepareStatement(FilterEventAdapter.java:122)
at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:568)
at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:341)
at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:349)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.ibatis.logging.jdbc.ConnectionLogger.invoke(ConnectionLogger.java:55)
at com.sun.proxy.$Proxy137.prepareStatement(Unknown Source)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.instantiateStatement(PreparedStatementHandler.java:86)
at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:88)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.prepare(RoutingStatementHandler.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
at com.sun.proxy.$Proxy136.prepare(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
at com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor.intercept(PaginationInterceptor.java:132)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
at com.sun.proxy.$Proxy136.prepare(Unknown Source)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
... 34 more
Caused by: com.alibaba.druid.sql.parser.ParserException: syntax error, expect RPAREN, actual IDENTIFIER pos 949, line 29, column 23, token IDENTIFIER sccount
at com.alibaba.druid.sql.parser.SQLExprParser.accept(SQLExprParser.java:2742)
at com.alibaba.druid.sql.parser.SQLExprParser.parseAggregateExpr(SQLExprParser.java:1520)
at com.alibaba.druid.sql.parser.SQLExprParser.methodRest(SQLExprParser.java:1124)
at com.alibaba.druid.sql.parser.SQLExprParser.parseSelectItem(SQLExprParser.java:3339)
at com.alibaba.druid.sql.parser.SQLSelectParser.parseSelectList(SQLSelectParser.java:675)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlSelectParser.query(MySqlSelectParser.java:181)
at com.alibaba.druid.sql.parser.SQLSelectParser.query(SQLSelectParser.java:236)
at com.alibaba.druid.sql.parser.SQLSelectParser.select(SQLSelectParser.java:88)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlSelectParser.parseTableSource(MySqlSelectParser.java:246)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlSelectParser.parseFrom(MySqlSelectParser.java:89)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlSelectParser.query(MySqlSelectParser.java:193)
at com.alibaba.druid.sql.parser.SQLSelectParser.query(SQLSelectParser.java:236)
at com.alibaba.druid.sql.parser.SQLSelectParser.select(SQLSelectParser.java:88)
at com.alibaba.druid.sql.parser.SQLExprParser.primary(SQLExprParser.java:655)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser.primary(MySqlExprParser.java:198)
at com.alibaba.druid.sql.parser.SQLExprParser.expr(SQLExprParser.java:154)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser.parseReplace(MySqlStatementParser.java:2332)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser.parseStatementListDialect(MySqlStatementParser.java:900)
at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:517)
at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:182)
at com.alibaba.druid.wall.WallProvider.checkInternal(WallProvider.java:624)
at com.alibaba.druid.wall.WallProvider.check(WallProvider.java:578)
at com.alibaba.druid.wall.WallFilter.checkInternal(WallFilter.java:793)
... 75 more
后来查阅Druid的文档以及网上的一些资料发现,Druid对于这种语法,会识别为两个语句 即:REPLACE INTO xxx 为一句 后面的 SELECT ... 也是一句独立的SQL,而Druid默认的过滤器 `WallFilter` 里默认会拦截多条SQL一起执行的情况,并抛出异常。
解决方案:配置Druid拦截器,开启 是否允许一次执行多条语句的配置:
package com.hm.spss.config;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
/**
* @Description:
*/
@Configuration
public class DruidDBConfig {
@Bean
public ServletRegistrationBean druidServlet() {
ServletRegistrationBean reg = new ServletRegistrationBean();
reg.setServlet(new StatViewServlet());
reg.addUrlMappings("/druid/*");
//reg.addInitParameter("allow", "127.0.0.1"); //白名单
reg.addInitParameter("resetEnable","false");
return reg;
}
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new WebStatFilter());
Map initParams = new HashMap();
//设置忽略请求
initParams.put("exclusions", "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*");
filterRegistrationBean.setInitParameters(initParams);
filterRegistrationBean.addInitParameter("profileEnable", "true");
filterRegistrationBean.addInitParameter("principalCookieName","USER_COOKIE");
filterRegistrationBean.addInitParameter("principalSessionName","");
filterRegistrationBean.addInitParameter("aopPatterns","com.example.demo.service");
filterRegistrationBean.addUrlPatterns("/*");
return filterRegistrationBean;
}
// 配置事物管理器
@Bean
public DataSourceTransactionManager transactionManager(){
return new DataSourceTransactionManager(new DruidDataSource());
}
@Bean
public WallFilter wallFilter(){
WallFilter wallFilter = new WallFilter();
wallFilter.setConfig(wallConfig());
return wallFilter;
}
@Bean
public WallConfig wallConfig(){
WallConfig wallConfig = new WallConfig();
wallConfig.setMultiStatementAllow(true);//允许一次执行多条语句
wallConfig.setNoneBaseStatementAllow(true);//是否允许非以上基本语句的其他语句
wallConfig.setStrictSyntaxCheck(false);//是否进行严格的语法检测
return wallConfig;
}
}