java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax;报错解决方式

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 '-category 
 WHERE  del_flag=0' at line 1
    at ***.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.25.jar:8.0.25]
    at ***.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.25.jar:8.0.25]
    at ***.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) ~[mysql-connector-java-8.0.25.jar:8.0.25]
    at ***.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:370) ~[mysql-connector-java-8.0.25.jar:8.0.25]
    at ***.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44) ~[HikariCP-4.0.3.jar:na]
    at ***.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java) ~[HikariCP-4.0.3.jar:na]
    at sun.reflect.NativeMethodA***essorImpl.invoke0(Native Method) ~[na:1.8.0_271]
    at sun.reflect.NativeMethodA***essorImpl.invoke(NativeMethodA***essorImpl.java:62) ~[na:1.8.0_271]
    at sun.reflect.DelegatingMethodA***essorImpl.invoke(DelegatingMethodA***essorImpl.java:43) ~[na:1.8.0_271]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_271]
    at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) ~[mybatis-3.5.7.jar:3.5.7]
    at ***.sun.proxy.$Proxy81.execute(Unknown Source) ~[na:na]
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64) ~[mybatis-3.5.7.jar:3.5.7]
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) ~[mybatis-3.5.7.jar:3.5.7]
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) ~[mybatis-3.5.7.jar:3.5.7]
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) ~[mybatis-3.5.7.jar:3.5.7]
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) ~[mybatis-3.5.7.jar:3.5.7]
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) ~[mybatis-3.5.7.jar:3.5.7]
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89) ~[mybatis-3.5.7.jar:3.5.7]
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151) ~[mybatis-3.5.7.jar:3.5.7]
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145) ~[mybatis-3.5.7.jar:3.5.7]
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) ~[mybatis-3.5.7.jar:3.5.7]
    at sun.reflect.NativeMethodA***essorImpl.invoke0(Native Method) ~[na:1.8.0_271]
    at sun.reflect.NativeMethodA***essorImpl.invoke(NativeMethodA***essorImpl.java:62) ~[na:1.8.0_271]
    at sun.reflect.DelegatingMethodA***essorImpl.invoke(DelegatingMethodA***essorImpl.java:43) ~[na:1.8.0_271]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_271]
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) ~[mybatis-spring-2.0.6.jar:2.0.6]
    at ***.sun.proxy.$Proxy63.selectList(Unknown Source) ~[na:na]
    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) ~[mybatis-spring-2.0.6.jar:2.0.6]
    at ***.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:166) ~[mybatis-plus-core-3.4.3.jar:3.4.3]
    at ***.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:77) ~[mybatis-plus-core-3.4.3.jar:3.4.3]
    at ***.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) ~[mybatis-plus-core-3.4.3.jar:3.4.3]
    at ***.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) ~[mybatis-plus-core-3.4.3.jar:3.4.3]
    at ***.sun.proxy.$Proxy67.selectList(Unknown Source) ~[na:na]
    at ***.baomidou.mybatisplus.extension.service.IService.list(IService.java:279) ~[mybatis-plus-extension-3.4.3.jar:3.4.3]
    at ***.baomidou.mybatisplus.extension.service.IService.list(IService.java:288) ~[mybatis-plus-extension-3.4.3.jar:3.4.3]
  报错原因:

 我的数据表名字为lxs-category,在使用LambdaQueryWrapper 进行查询数据库时,会把-category当成一个命令,在控制台报1064 - 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 '-category   WHERE  del_flag=0' at line 1

解决方式

将lxs-category改为lxs_category,就能正确运行了

 

转载请说明出处内容投诉
CSS教程_站长资源网 » java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax;报错解决方式

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买