Mybaties Update 不允许的操作

环境:Spring+Mybaties3.X

 /**
     * @param entity
     * 使用CRUDTemplate操作
     */
    @UpdateProvider(type = CRUDTemplate.class, method = "update")  
    public int update(T entity);
 public String update(Object obj) throws Exception {
        BEGIN();

        UPDATE(getEntityTable(obj).getName());
        SET(getUpdateSetStr(obj));
        WHERE("id=#{id}");
        String sql = SQL();

        logger.debug("sql : "+sql);
        return sql;
    }

org.springframework.jdbc.UncategorizedSQLException: Error getting generated key or setting result to parameter object. Cause: java.sql.SQLException: 不允许的操作
; uncategorized SQLException for SQL []; SQL state [null]; error code [17090]; 不允许的操作; nested exception is java.sql.SQLException: 不允许的操作
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:71)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365)
at $Proxy18.update(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:251)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:54)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
at $Proxy24.update(Unknown Source)
at com.tuban.framework.service.impl.BaseServiceImpl.update(BaseServiceImpl.java:69)
at com.tuban.framework.service.impl.BaseServiceImpl$$FastClassByCGLIB$$cb0b41cc.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
at com.tuban.core.role.service.impl.RoleServiceImpl$$EnhancerByCGLIB$$70da1b82.update()
at mybatis.MybatisTest.testAdd(MybatisTest.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.sql.SQLException: 不允许的操作
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.OracleStatement.getGeneratedKeys(OracleStatement.java:4568)
at org.apache.commons.dbcp.DelegatingStatement.getGeneratedKeys(DelegatingStatement.java:315)
at org.apache.commons.dbcp.DelegatingStatement.getGeneratedKeys(DelegatingStatement.java:315)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:85)
at $Proxy45.getGeneratedKeys(Unknown Source)
at org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processBatch(Jdbc3KeyGenerator.java:51)
at org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processAfter(Jdbc3KeyGenerator.java:45)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:48)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62)
at $Proxy43.update(Unknown Source)
at org.apache.ibatis.executor.ReuseExecutor.doUpdate(ReuseExecutor.java:50)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:355)
... 43 more

有遇到过的吗?费解

2个回答

已解决,太变态了,由于MYbaties默认useGeneratedKeys=true,所以在insert和update的时候,都生成KEY,然后注入。所以这就是为什么update的时候会失败,同理,在insert的时候,插入成功后,getId()也会发现,这个Id并不是我们注入的ID,而是mybaties帮我们生成的ID,所以在使用代理方法执行SQL的时候,需要如下设置:

 /**
     * @param entity
     * 使用CRUDTemplate操作
     */
    @UpdateProvider(type = CRUDTemplate.class, method = "update") 
    **@Options(useGeneratedKeys=false )**
    public int update(T entity);
Vito_Wang
Vito_Wang 感谢解答!
一年多之前 回复
interesting2012
interesting2012 您说得太对了!!非常感谢您的帮助!!
接近 4 年之前 回复

贴出执行的SQL语句,结果是提示执行成功的:

 2015-02-23 02:41:13,407 [main] DEBUG work.mybatis.mapperTemplate.CRUDTemplate -sql : UPDATE ic_role
SET NAME=#{name},MODIFY_TIME=#{modifyTime},MODIFIER=#{modifier},STATE=#{state}
WHERE (id=#{id})
2015-02-23 02:41:13,407 [main] DEBUG ore.role.dao.RoleMapper.updateByProvider -==>  Preparing: UPDATE ic_role SET NAME=?,MODIFY_TIME=?,MODIFIER=?,STATE=? WHERE (id=?) 
2015-02-23 02:41:13,516 [main] DEBUG ore.role.dao.RoleMapper.updateByProvider -==> Parameters: test_update2222(String), 2015-02-23 02:41:13.407(Timestamp), 1(String), 1(String), 8debb846eb1d493aa25bba1fc5fb0da5(String)
2015-02-23 02:41:13,516 [main] DEBUG ore.role.dao.RoleMapper.updateByProvider -<==    Updates: 1
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

mybatis update不正常

架构 :springmvc+mybatis <update id="batchUpdatePackageTicketList"> UPDATE t_cus_package_sub_info set F_VALUE = (F_VALUE - 1) WHERE F_MAIN_ID ='123456' </update> 执行前数据库中 F_VALUE的值是1 ,执行后为什么F_VALUE的值变成-1了,不明白为什么?求大神解答 我用的是MYSQL数据库,F_VALUE类型是bigint

mybatis update操作报错

我单元测试数据的更新操作,一直报错java.sql.SQLException: Parameter index out of range (13 > number of parameters, which is 12) 表结构: DROP TABLE IF EXISTS `business`; CREATE TABLE `business`( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT `主键`, `img_file_name` varchar(200) DEFAULT NULL COMMENT `图片文件名`, `title` varchar(50) DEFAULT NULL COMMENT `标题`, `subtitle` varchar(100) DEFAULT NULL COMMENT`副标题`, `price` decimal(11,2) DEFAULT NULL COMMENT`价格(单位:元)`, `distance` int(11) DEFAULT NULL COMMENT`距离(单位:米)`, `number` int(11) DEFAULT NULL COMMENT `已售数量`, `desc` varchar(500) DEFAULT NULL COMMENT `描述`, `city` varchar(16) DEFAULT NULL COMMENT `城市`, `catefory` varchar(16) DEFAULT NULL COMMENT `类别`, `start_total_num` int(11) DEFAULT NULL COMMENT `评论星星总数`, `comment_total_num` int(11) DEFAULT NULL COMMENT `评论总次数`, PRIMARY KEY (`id`) )ENGINE=InnoDB DEFAULT CHARSET=utf8; bean: private Long id; private String imgFileName; private String title; private String subtitle; private Double price; private Integer distance; private Integer number; private String desc; private String city; private String category; private Long starTotalNum; private Long commentTotalNum; ``` mybatis的update: ```<update id="update"> update business b SET b.img_file_name=#{imgFileName},b.title=#{title},b.subtitle=#{subtitle},b.price=#{price} ,b.distance=#{distance},b.number=#{number},b.desc=#{desc},b.city=#{city},b.category=#{category},b.star_total_num=#{starTotalNum},b.comment_total_num=#{commentTotalNum} where b.id=#{id} </update> ``` 单元测试: @Test public void update(){ BusinessDto businessDto = new BusinessDto(); Long a = new Long(3); businessDto.setId(a); businessDto.setCity("北京"); businessDto.setDesc("啦啦啦啦啦啦"); businessService.modify(businessDto); } ``` ``` ```

mybatis+spring+strust2 后update操作不报错但没起效果

![图片说明](https://img-ask.csdn.net/upload/201603/16/1458123495_464225.jpg) 日志如上图 ![图片说明](https://img-ask.csdn.net/upload/201603/16/1458123847_571754.jpg) sql语句文件如上图 有两个疑问: 1 做insert操作无任何问题,update 操作不报错,就是更新无效果,数据还是原来的数据。 2 sql语句的配置xml文件中判断了if xxx!=null 但是日志里打印出来的sql还是有null (如图2)

Mybatis save and update 批量操作

我想在mybatis中批量更新操作一些数据,改数据库配置&allowMultiQueries=true是可以的,想知道用 ON DUPLICATE KEY UPDATE 可以批量操作吗?还有没有别的什么好方法?

mysql mybatis 执行update 返回影响行数错误

文章内容在:http://www.oschina.net/question/1244507_250862 我就不再次编辑了

Mybatis更新字段不生效

毕设做一个关于商城的项目。需求只要是更新到购物项里边的一些字段。 前端传值打印出来都没问题,看日志输出了sql语句,属性值没错,但是执行后proCount会变成0 ,subtotal的值没变。很是奇怪。直接上图。 ![图片说明](https://img-ask.csdn.net/upload/201804/25/1524670295_442081.png) ![图片说明](https://img-ask.csdn.net/upload/201804/25/1524670305_429972.png)

mybatis mysql update 返回影响行数错误

数据库有个订单表 有一行数据 order_id=1555(自增主键),有个标记字段order_mark=2 执行语句update t_order set order_mark = 2 where order_id=1555 使用mysql自带的client工具 Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0 使用Navicat for MySQL工具返回 [SQL] update t_order set order_mark = 2 where order_id=1555 受影响的行: 0 时间: 0.002s 使用工具 datastudio 返回 1 record(s) affected 在项目中 项目源码: int i = orderDAO.updateOrderMark(orderId, ORDER_MARK.CHEAT.ordinal()); if(i==1){ int userId = order.getDriverId(); 此处的返回的i=1; debug打印执行的sql ![update=1](https://img-ask.csdn.net/upload/201509/14/1442192135_33720.png) 求解释为什么返回的影响行数会是 1.而不是0

mybatis 如何用update修改关联表Service业务层怎么实现

## /**软件环境**/ 框架:spring springMVC mybatis 数据库:mysql ## /**报错信息**/ ![图片说明](https://img-ask.csdn.net/upload/201903/04/1551665050_386888.png) ## /**代码提示**/ //数据层mybatis xml文件 ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.app.dao.mapper.MemberPermissionMapper"> <resultMap type="MemberPermission" id="MemberPermission"> <id column="id" property="id"/> <result column="member_id" property="member_id"/> <result column="ttys" property="ttys"/> <result column="key" property="key"/> <result column="lose_time" property="lose_time"/> <result column="note" property="note"/> <result column="update_time" property="update_time"/> <!-- 关联member表 --> <association property="member" javaType="com.app.bean.Member"> <id column="member_id" property="id"/> <result column="phone" property="phone"/> <result column="name" property="name"/> <result column="password" property="password"/> </association> </resultMap> <update id="updateMemberLoginPermission" parameterType="map"> UPDATE dt_member_permission AS t1 LEFT JOIN dt_member AS t2 ON t1.member_id=t2.id <set> <if test="key!=null and key !=''">t1.key=#{key}, </if> </set> WHERE t1.ttys=#{key} AND t2.phone=#{phone} AND t2.password=#{password} </update> ``` //service业务层接口实现类提示 phone和newpwd字段是在关联表member里面 ``` @Override public int updateMemberLoginPermission( String ttys, String phone, String newpwd, String key_dm) { MemberPermission memberPermission= new MemberPermission(); memberPermission.setTtys(ttys); memberPermission.setKey_dm(key_dm); Member member = new Member(); member.setPhone(phone); member.setPassword(newpwd); return memberPermissionDao.updateMemberLoginPermission(memberPermission,member); } ``` //javabean实体类提示 ``` package com.app.bean; import java.util.Date; /** * 用户权限组合表 * pjc * 2019.2.25 */ public class MemberPermission { private int id; private int member_id; private String ttys;//终端类型 private String key; private Date lose_time; private String note; private Date update_time; public MemberPermission() { } public MemberPermission(int id, int member_id, String ttys, String key, Date lose_time, String note, Date update_time) { this.id = id; this.member_id = member_id; this.ttys = ttys; this.key = key; this.lose_time = lose_time; this.note = note; this.update_time = update_time; } public int getId() { return id; } /**后面省略** ``` //关联表Javabean提示 ``` public class Member { private int id; private String name; private String password; private int gender; private Date birthday; private String phone; private String email; private Date regtime; private Date losetime; private Date losetime_jl; private Date losetime_tz; private Date losetime_bj; private Date losetime_sz; private String nickname; private String head; private int status; private int type; private String note; private String departments; private String hospital; private String province; private String city; private String country; private String key;//用户授权码实现单点登录 private String key_jl;//实现经络app单点登录 private String key_tz;//实现体质app单点登录 private String key_bj;//实现保健机构用户单点登录 private String key_sz;//实现手诊用户单点登录 private Date record_time; private String advice;//医师建议 ``` //mapper.java文件提示 ![图片说明](https://img-ask.csdn.net/upload/201903/04/1551686590_996340.png) ## /**尝试过的办法1: key字段已经统一改为key_dm和数据库实体类全部统一 去掉@param注解 修改mybatis.xml**/ //dao层接口代码提示 mapper.java文件 ``` public interface MemberPermissionMapper { public int updateMemberLoginPermission(MemberPermission memberPermission,Member member);//根据终端类型 用户手机号密码修改动态key 关联表 } ``` //service层接口提示 ``` package com.app.service; import java.util.Date; import java.util.List; import java.util.Map; import com.app.bean.Member; public interface MemberService { public int updateMemberLoginPermission(String ttys,String phone, String newpwd, String key_dm); } ``` //service层接口实现类提示 ``` @Override public int updateMemberLoginPermission( String ttys, String phone, String newpwd, String key_dm) { MemberPermission memberPermission= new MemberPermission(); memberPermission.setTtys(ttys); memberPermission.setKey_dm(key_dm); Member member = new Member(); member.setPhone(phone); member.setPassword(newpwd); return memberPermissionDao.updateMemberLoginPermission(memberPermission,member); } ``` //mybatis.xml ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.app.dao.mapper.MemberPermissionMapper"> <resultMap type="com.app.bean.MemberPermission" id="MemberPermission"> <id column="id" property="id"/> <result column="member_id" property="member_id"/> <result column="ttys" property="ttys"/> <result column="key_dm" property="key_dm"/> <result column="lose_time" property="lose_time"/> <result column="note" property="note"/> <result column="update_time" property="update_time"/> <!-- 关联member表 --> <association property="member" javaType="com.app.bean.Member"> <id column="member_id" property="id"/> <result column="phone" property="phone"/> <result column="name" property="name"/> <result column="password" property="password"/> </association> </resultMap> <update id="updateMemberLoginPermission" parameterType="com.app.bean.Member"> UPDATE dt_member_permission AS t1 LEFT JOIN dt_member AS t2 ON t1.member_id=t2.id <set> <if test="key_dm!=null and key_dm !=''">t1.key_dm=#{key_dm}, </if> </set> WHERE t1.ttys=#{ttys} AND t2.phone=#{phone} AND t2.password=#{password} </update> ``` //报错提示 ![图片说明](https://img-ask.csdn.net/upload/201903/05/1551755075_567480.png) ## /**尝试方法2 已解决: 关联对象传参问题**/ 别用实体类传参,使用map。 Map map = new HashMap(); map.put("ttys",ttys); map.put("phone",phone); map.put("key_dm",key_dm); map.put("password",password); xml中的update语句修改成: UPDATE dt_member_permission AS t1 LEFT JOIN dt_member AS t2 ON t1.member_id=t2.id t1.key_dm=#{key_dm} WHERE t1.ttys=#{ttys} AND t2.phone=#{phone} AND t2.password=#{password}

mybatis sqlserver @update 问题

String UPDATE_NEWS = "update T_NEWS set TITLE=#{title},CONTENTS=#{content},RDATE=#{date},ISSHOW=#{isShow}" + ",BIGPIC=#{bigPic} " + " where ID=#{id}"; @Update(UPDATE_NEWS) int updateNews(CentralNews News); mapper里接口是这样的 执行后更新是更新到数据库里了,但是报了这个异常 nested exception is org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'id' of 'class com.seu.xu.model.CentralNews' with value 'null' Cause: java.lang.IllegalArgumentException

求助:Mybatis不提交更新是怎么回事???

附上日志: DEBUG [main] - Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter. DEBUG [main] - PooledDataSource forcefully closed/removed all connections. DEBUG [main] - PooledDataSource forcefully closed/removed all connections. DEBUG [main] - PooledDataSource forcefully closed/removed all connections. DEBUG [main] - PooledDataSource forcefully closed/removed all connections. DEBUG [main] - Opening JDBC Connection DEBUG [main] - Created connection 38544126. DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@24c22fe] DEBUG [main] - ==> Preparing: UPDATE N1 SET NAME=? WHERE ID=? DEBUG [main] - ==> Parameters: xu(String), 1(Integer) DEBUG [main] - <== Updates: 1 到这里就断了,什么原因???

mybatis更新操作,是用set和if标签吗?

RT,如果用户就是要修改成空字符串,怎么办,实际项目中一般是怎么操作的?

MYBATIS 批量update 报错的问题

批量update,很简单的sql语句,可是一直在报错。不知道为什么,求助!!! <update id="updateStudentPointLevelBatch" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="" close="" separator=";"> update student_point_level s set s.score = #{item.score} where s.id = #{item.id} </foreach> </update> 按照打印出来的sql,贴到front里运行的也都是对的.... ### Error updating database. Cause: 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 'update student_point_level s set s.score = 16 where s.id = 19' at line 7 ### The error may involve com.supert.st.dao.StudentPointLevelMapper.updateStudentPointLevelBatch-Inline ### The error occurred while setting parameters ### SQL: update student_point_level s set s.score = ? where s.id = ? ; update student_point_level s set s.score = ? where s.id = ? ### Cause: 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 'update student_point_level s set s.score = 16 where s.id = 19' at line 7 ; bad SQL grammar []; nested exception is 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 'update student_point_level s set s.score = 16 where s.id = 19' at line 7

mybatis字段要更新为null ,要怎么处理啊

数据库一个字段要更新为null ,不能更新空串,字段为外键,要怎么处理啊!

mybatis insert或者update时候 时间、人ID字段预处理如何实现

我现在想实现一个功能描述如下: 我们一般操作一个模块,有新增、修改 那一般操作对象有 create_user/create_date,或者update_user/update_date这样的时间 与“操作人” 而时间,一般是默认系统时间 操作人,一般都是从session中获取登录人的信息赋值。 现在我每做一个模块都要setDate(new Date) setUser(request.getsession.getAttribute(“user”).getUserId); 我觉得很麻烦,不够通用,想请教有大神能想个办法,每次mybaits做insert 和update 时间字段与操作人字段的时候,能默认赋值

mybatis存储过程中第二update执行速度很慢导致,最终在存储过程中没有执行,求解决方案

create procedure assignOrder(in userId BIGINT,in arrangBy BIGINT,in meg VARCHAR(1000),out count BIGINT) begin IF userId is not NULL and arrangBy is not NULL THEN UPDATE apply_flow as a set arrange_by = userId,remark=meg,response_by=userId where arrange_by=arrangBy and id in( select b.id from apply_base b where a.id=b.id and b.status_no=1 ); update queue_resume_conversion set deal_by=userId where is_archive=1 and id in ( select conversion_id from apply_base base LEFT JOIN apply_flow flow on base.id=flow.id and base.status_no=1 where arrange_by=arrangBy); set count=1; ELSE set count=0; end IF; SELECT count; END 第二个update太慢的缘故还是,什么缘故,反正存储过程执行结果,但是第二个update没有任何效果

mybatis 执行 INSERT … ON DUPLICATE KEY UPDATE

mybatis 在执行 INSERT … ON DUPLICATE KEY UPDATE 格式的语句的时候 没有报错,库表也没插入数据,数据库是mysql 用mysql客户端执行这条语句的时候却是能插入的 是因为myBatis不支持吗? 语句示例: INSERT INTO test (main_id,score,totalCount) VALUES (123,5.0,12345) ON DUPLICATE KEY UPDATE score=VALUES(score), totalCount=VALUES(totalCount) main_id是主键,以上语在mysql客户端执行能正确插入或更新 <insert id="insertOrUpdate" parameterType="这里就不写了"> INSERT INTO test (main_id,score,totalCount) VALUES (456,5.0,12345) <!--这里有个参数是456,同上面一条的123不一样--> ON DUPLICATE KEY UPDATE score=VALUES(score), totalCount=VALUES(totalCount) </insert> 这是mybatis里面执行的语句,为了直观些,我直接写了一条死语句进来。 同样的两条语句,在mybatis里面执行的时候也不报错,但是数据库却插不进去,也不能更新 求解!

mybatis 如何在 mapper 中实现 insertorupdate 的逻辑

想在mybatis 的 mapper 中实现 insert or update 的逻辑,如何实现 ? 第一步 select count 第二步 判断 count ,如果 0 ,insert ,如果有 update 这个逻辑要封装在一个 sql中,而不是 在service 中调用多个 dao 实现。 请教 ,感谢 。

mybatis+oracle 一条update方法一直报sql命令为结束错误,不知道怎么回事

<update id="assignPlural" > update exam_task set teacherId=#{teacherId} where id in ( select id from ( select id , row_number() over (partition by answerId order by null) m from ( select id , answerId from exam_task where answerId in (select id from exam_answer where questionId =#{questionId}) and answerId not in (select answerId from exam_task where teacherId=#{teacherId}) ) ) where m=1 ) where rownum &lt;=#{assignNum} </update>

spring+mybatis异常不回滚

代码如下: applicationContext-mybatis.xml ``` <bean id="sSF" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath:com/telchina/**/*.xml"></property> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.telchina"></property> <property name="sqlSessionFactoryBeanName" value="sSF"></property> </bean> <!-- 事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" > <property name="dataSource" ref="dataSource" /> </bean> <!-- 拦截器方式配置事务 --> <tx:advice id="transactionAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.RuntimeException"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="transactionPointcut" expression="execution(* com.telchina.app.service.impl.*Impl.*(..))" /> <aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" /> </aop:config> ``` ``` @Service("demoService") public class DemoServiceImpl implements DemoService { @SuppressWarnings("rawtypes") @Override public String rollbackTest(List demoList) { // TODO Auto-generated method stub Iterator itr = demoList.iterator(); while (itr.hasNext()) { Map demoMap = (Map) itr.next(); demoMapper.updateDemo(demoMap); throw new RuntimeException("rollbackTest"); } return ""; } } ``` List中传入了两个对象,总是能更新一个,事务不回滚,愁死了,求各位大侠指点!!!!

2019 Python开发者日-培训

2019 Python开发者日-培训

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

设计模式(JAVA语言实现)--20种设计模式附带源码

设计模式(JAVA语言实现)--20种设计模式附带源码

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

java后台+微信小程序 实现完整的点餐系统

java后台+微信小程序 实现完整的点餐系统

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

2019 AI开发者大会

2019 AI开发者大会

玩转Linux:常用命令实例指南

玩转Linux:常用命令实例指南

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

4小时玩转微信小程序——基础入门与微信支付实战

4小时玩转微信小程序——基础入门与微信支付实战

Git 实用技巧

Git 实用技巧

Python数据清洗实战入门

Python数据清洗实战入门

使用TensorFlow+keras快速构建图像分类模型

使用TensorFlow+keras快速构建图像分类模型

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

程序员的算法通关课:知己知彼(第一季)

程序员的算法通关课:知己知彼(第一季)

MySQL数据库从入门到实战应用

MySQL数据库从入门到实战应用

机器学习初学者必会的案例精讲

机器学习初学者必会的案例精讲

手把手实现Java图书管理系统(附源码)

手把手实现Java图书管理系统(附源码)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

.net core快速开发框架

.net core快速开发框架

玩转Python-Python3基础入门

玩转Python-Python3基础入门

Python数据挖掘简易入门

Python数据挖掘简易入门

微信公众平台开发入门

微信公众平台开发入门

程序员的兼职技能课

程序员的兼职技能课

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

HoloLens2开发入门教程

HoloLens2开发入门教程

微信小程序开发实战

微信小程序开发实战

Java8零基础入门视频教程

Java8零基础入门视频教程

相关热词 c#跨线程停止timer c#批量写入sql数据库 c# 自动安装浏览器 c#语言基础考试题 c# 偏移量打印是什么 c# 绘制曲线图 c#框体中的退出函数 c# 按钮透明背景 c# idl 混编出错 c#在位置0处没有任何行
立即提问