MyBatis 遇到 Error updating database.问题
这是我第一次想要在 CSDN 社区发表博客,原因呢是因为我也用了 CSDN 两年了,非常感谢它帮助我解决了很多问题,但是呢,每个人和每个人的问题都会有一些出入,所以呢,我想把我遇到的问题并且得以解决的分享给大家!
问题
我是在听了老师讲的 MyBatis 后想要使用动态 SQL 语句执行插入操作,但是我自认为没有问题的 sql 语句却出现了一个非常呆呆的错误,就是我的下面这条语句的最后一个 test="userRole != null and userRole ! = ''" 中的感叹号写成了中文的,这个困扰了我好久都没有找出来,后来经过一点点调试发现的。
<update id="modify" parameterType="User">update smbms_user<trim prefix="set" suffixOverrides=","><if test="userCode != null and userCode != ''">userCode = #{userCode},</if><if test="userName != null and userName != ''">userName = #{userName},</if><if test="userPassword != null and userPassword != ''">userPassword = #{userPassword},</if><if test="gender != null and gender != ''">gender = #{gender},</if><if test="birthday != null and birthday != ''">birthday = #{birthday},</if><if test="phone != null and phone != ''">phone = #{phone},</if><if test="address != null and address != ''">address = #{address},</if><if test="userRole != null and userRole ! = ''">userRole = #{userRole},</if></trim>where id=#{id}
</update>
解决办法
只需要将test="userRole != null and userRole ! = ''" 中的感叹号改成英文的即可。
下面看一下我的错误提示吧
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'userRole != null and userRole ! = '''. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: userRole != null and userRole ! = '' [org.apache.ibatis.ognl.ParseException: Encountered " "!" "! "" at line 1, column 31.
Was expecting one of:
<EOF>
"," ...
"=" ...
"?" ...
"||" ...
"or" ...
"&&" ...
"and" ...
"|" ...
"bor" ...
"^" ...
"xor" ...
"&" ...
"band" ...
"==" ...
"eq" ...
"!=" ...
"neq" ...
"<" ...
"lt" ...
">" ...
"gt" ...
"<=" ...
"lte" ...
">=" ...
"gte" ...
"in" ...
"not" ...
"<<" ...
"shl" ...
">>" ...
"shr" ...
">>>" ...
"ushr" ...
"+" ...
"-" ...
"*" ...
"/" ...
"%" ...
"instanceof" ...
"." ...
"(" ...
"[" ...
<DYNAMIC_SUBSCRIPT> ...
"(" ...
]
### The error may exist in mapper/UserMapper.xml
### The error may involve com.smbms.mapper.UserMapper.modify
### The error occurred while executing an update
### Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'userRole != null and userRole ! = '''. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: userRole != null and userRole ! = '' [org.apache.ibatis.ognl.ParseException: Encountered " "!" "! "" at line 1, column 31.
Was expecting one of:
<EOF>
"," ...
"=" ...
"?" ...
"||" ...
"or" ...
"&&" ...
"and" ...
"|" ...
"bor" ...
"^" ...
"xor" ...
"&" ...
"band" ...
"==" ...
"eq" ...
"!=" ...
"neq" ...
"<" ...
"lt" ...
">" ...
"gt" ...
"<=" ...
"lte" ...
">=" ...
"gte" ...
"in" ...
"not" ...
"<<" ...
"shl" ...
">>" ...
"shr" ...
">>>" ...
"ushr" ...
"+" ...
"-" ...
"*" ...
"/" ...
"%" ...
"instanceof" ...
"." ...
"(" ...
"[" ...
<DYNAMIC_SUBSCRIPT> ...
"(" ...
]
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:196)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:67)
at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:145)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86)
at com.sun.proxy.$Proxy6.modify(Unknown Source)
at TestUser.TestQuery(TestUser.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.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'userRole != null and userRole ! = '''. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: userRole != null and userRole ! = '' [org.apache.ibatis.ognl.ParseException: Encountered " "!" "! "" at line 1, column 31.
Was expecting one of:
<EOF>
"," ...
"=" ...
"?" ...
"||" ...
"or" ...
"&&" ...
"and" ...
"|" ...
"bor" ...
"^" ...
"xor" ...
"&" ...
"band" ...
"==" ...
"eq" ...
"!=" ...
"neq" ...
"<" ...
"lt" ...
">" ...
"gt" ...
"<=" ...
"lte" ...
">=" ...
"gte" ...
"in" ...
"not" ...
"<<" ...
"shl" ...
">>" ...
"shr" ...
">>>" ...
"ushr" ...
"+" ...
"-" ...
"*" ...
"/" ...
"%" ...
"instanceof" ...
"." ...
"(" ...
"[" ...
<DYNAMIC_SUBSCRIPT> ...
"(" ...
]
at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:48)
at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:32)
at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:34)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.lambda$apply$0(MixedSqlNode.java:32)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)
at org.apache.ibatis.scripting.xmltags.TrimSqlNode.apply(TrimSqlNode.java:55)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.lambda$apply$0(MixedSqlNode.java:32)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)
at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:39)
at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:305)
at org.apache.ibatis.executor.statement.BaseStatementHandler.<init>(BaseStatementHandler.java:64)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.<init>(PreparedStatementHandler.java:41)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.<init>(RoutingStatementHandler.java:46)
at org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:681)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)
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:194)
... 29 more
Caused by: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: userRole != null and userRole ! = '' [org.apache.ibatis.ognl.ParseException: Encountered " "!" "! "" at line 1, column 31.
Was expecting one of:
<EOF>
"," ...
"=" ...
"?" ...
"||" ...
"or" ...
"&&" ...
"and" ...
"|" ...
"bor" ...
"^" ...
"xor" ...
"&" ...
"band" ...
"==" ...
"eq" ...
"!=" ...
"neq" ...
"<" ...
"lt" ...
">" ...
"gt" ...
"<=" ...
"lte" ...
">=" ...
"gte" ...
"in" ...
"not" ...
"<<" ...
"shl" ...
">>" ...
"shr" ...
">>>" ...
"ushr" ...
"+" ...
"-" ...
"*" ...
"/" ...
"%" ...
"instanceof" ...
"." ...
"(" ...
"[" ...
<DYNAMIC_SUBSCRIPT> ...
"(" ...
]
at org.apache.ibatis.ognl.Ognl.parseExpression(Ognl.java:181)
at org.apache.ibatis.scripting.xmltags.OgnlCache.parseExpression(OgnlCache.java:55)
at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:46)
... 48 more
Caused by: org.apache.ibatis.ognl.ParseException: Encountered " "!" "! "" at line 1, column 31.
Was expecting one of:
<EOF>
"," ...
"=" ...
"?" ...
"||" ...
"or" ...
"&&" ...
"and" ...
"|" ...
"bor" ...
"^" ...
"xor" ...
"&" ...
"band" ...
"==" ...
"eq" ...
"!=" ...
"neq" ...
"<" ...
"lt" ...
">" ...
"gt" ...
"<=" ...
"lte" ...
">=" ...
"gte" ...
"in" ...
"not" ...
"<<" ...
"shl" ...
">>" ...
"shr" ...
">>>" ...
"ushr" ...
"+" ...
"-" ...
"*" ...
"/" ...
"%" ...
"instanceof" ...
"." ...
"(" ...
"[" ...
<DYNAMIC_SUBSCRIPT> ...
"(" ...
at org.apache.ibatis.ognl.OgnlParser.generateParseException(OgnlParser.java:3232)
at org.apache.ibatis.ognl.OgnlParser.jj_consume_token(OgnlParser.java:3098)
at org.apache.ibatis.ognl.OgnlParser.topLevelExpression(OgnlParser.java:19)
at org.apache.ibatis.ognl.Ognl.parseExpression(Ognl.java:179)
... 50 more
MyBatis 遇到 Error updating database.问题相关推荐
- 运行mybatis时显示报错:Error updating database. Cause: java.sql.SQLException: Error setting driver on
在运行mybatis测试类的时候,结果报错; Error updating database. Cause: java.sql.SQLException: Error setting driver o ...
- SSM Mybatis将新增数据写入数据库时出现的500状态码:Error updating database.的可能...
关于maven下ssm整合的项目推荐这篇博客:https://www.cnblogs.com/yiye/p/5969157.html 今日在ssm下的将新增数据写回数据库时遇到不少的问题,现作记录 如 ...
- ### Error updating database. Cause: java.sql.SQLException: Incorrect integer value: ‘**‘ for column
类型 异常报告消息 Request processing failed; nested exception is org.apache.ibatis.exceptions.PersistenceExc ...
- 解决及分析:MySQL的 Error updating database. Cause: java.sql.SQLException: You can’t specify target table
一.项目从Oracle迁移到MySQL时,报错:Error updating database. Cause: java.sql.SQLException: You can't specify tar ...
- Error updating database. Cause: java.sql.SQLSyntaxErrorException: Unknown column ‘experience_openne
项目场景: 项目使用了mybatis-plus进行数据库操作 问题描述 例如:后端无法插入数据,控制台输出如下信息 org.springframework.jdbc.BadSqlGrammarExce ...
- 使用mybatis-plus时候报错Error updating database.subject_parent_id‘ doesn‘t have a default value
使用mybatis-plus时候报错Error updating database. Cause: java.sql.SQLException: Field 'subject_parent_id' d ...
- Uncaught (in promise)Error: ### Error updating database. Cause :java.sql.SQLException:
Uncaught (in promise)Error: ### Error updating database. Cause :java.sql.SQLException: Field 'X ...
- Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Cannot add or up
报错描述: Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Cannot add ...
- org.springframework.jdbc.BadSqlGrammarException: Error updating database
最新文章
- 避免死锁的一些注意事项
- VirtualBox没有64位选项,无法安装64位的解决方法 感谢源作者
- WCF 服务端+客户端动态调用
- 小程序实践(三):九宫格实现及item跳转
- python selenium api_Selenium2+python自动化-查看selenium API
- 使用spring jdbc的batchUpdate功能提高性能
- pandas DataFrame数据筛选和切片
- Win32汇编——多线程
- 8086CPU工作原理
- HTML+CSS基础知识04
- unsigned char code 是什么
- 为什么我感觉永远满足不了公司的要求?
- 【es6】用map对数组对象中插入新的属性
- yy部分地区服务器升级维护,3月5日全区全服更新公告 - YY大皇帝 YY大皇帝独家官网 YY大皇帝新手卡...
- 计算机公式求时间差公式,excel 时间差计算方法
- Pearson皮尔逊,Kendall肯德尔和Spearman斯皮尔曼三种相关分析方法的异同
- 【V-REP自学笔记(八)】控制youBot抓取和移动物体
- adob animate_Chrome报告“ Adob​​e Flash Player已被阻止,因为它已过期。”
- DDN区块链节点升级公告
- 电脑屏上出现联想炫彩鸿蒙,最欢甚!联想P50手机炫彩版升级上市
热门文章
- 【渝粤教育】电大中专电子商务网站建设与维护 (28)作业 题库
- Imagination 推出最先进的光线追踪图形处理器(GPU)
- spssχ2检验_实用医学统计:配对四格表资料的χ2检验之SPSS操作篇
- HTML网页图片使用技巧集锦
- 【路科V0】systemVerilog基础11——随机变量
- 疯狂python讲义豆瓣评分_书榜 | 计算机书籍(9.9-9.15)销售排行榜
- 加密IC 在android 机子上的简单应用
- 流式数据武装零售业,打响“降维”反击战!
- 日有所思,夜有所梦:考研数学答卷有感
- python 画正弦曲线