NutzCN Logo
问答 后台未发现异常数据库却回滚了
发布于 1865天前 作者 wx_q3d8holor8dtsdrgl29h 1465 次浏览 复制 上一个帖子 下一个帖子
标签:

定义的sql是:

merge into TXZH_ALL t1
using (select '333333' user_id,
              '0401' systemid,
              '20191012110400' updatetime,
              '1' status,
              'adsfgdfgsf' cmuser_id,
              'cmcuseridno11' cmcuserid_no,
              '张三2' user_name,
              '' userext1,
              '' userext2,
              '' userext3
         from dual) t2
on (t1.user_id = t2.user_id and t1.systemid = t2.systemid)
when not matched then
  insert
  values
    (SEQ_TXZH_ALLID.nextval,
     TO_DATE(t2.updatetime, 'YYYY-MM-DD HH24:MI:SS'),
     t2.status,
     t2.cmuser_id,
     t2.cmcuserid_no,
     t2.user_id,
     t2.user_name,
     t2.userext1,
     t2.userext2,
     t2.userext3,
     t2.systemid)
when matched then
  update
     set t1.updatetime   = TO_DATE(t2.updatetime, 'YYYY-MM-DD HH24:MI:SS'),
         t1.status       = t2.status,
         t1.cmuser_id    = t2.cmuser_id,
         t1.cmcuserid_no = t2.cmcuserid_no,
         t1.user_name    = t2.user_name,
         t1.userext1     = t2.userext1,
         t1.userext2     = t2.userext2,
         t1.userext3     = t2.userext3

数据库中直接执行没问题;
java代码:

String sqlStr = String.format(gotSql().toString(),  userid, systemid, updatetime,status, cmuserid, cmcuseridno, username, userext1, userext2, userext3);
Sql sql = Sqls.create(sqlStr);
sql.forceExecQuery();							
dao.execute(sql);							
successSize++;

接口显示正常返回:

"data": {
        "err_msg": "",
        "err_code": "成功数据条数:1"
    }

用的是druid-1.1.21.jar,后台没发现报错。但是会回滚数据,没有commit。

2019-11-14 10:40:00,891 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - merge into TXZH_ALL t1 using (select '333333' user_id,'0401' systemid,'20191012110400' updatetime,'1' status,'adsfgdfgsf' cmuser_id,'cmcuseridno11' cmcuserid_no,'张三2' user_name,'' userext1,'' userext2,'' userext3 from dual) t2 on (t1.user_id = t2.user_id and t1.systemid = t2.systemid) when not matched then insert values (SEQ_TXZH_ALLID.nextval,TO_DATE(t2.updatetime,'YYYY-MM-DD HH24:MI:SS'),t2.status,t2.cmuser_id,t2.cmcuserid_no,t2.user_id,t2.user_name,t2.userext1,t2.userext2,t2.userext3,t2.systemid) when matched then update set t1.updatetime = TO_DATE(t2.updatetime,'YYYY-MM-DD HH24:MI:SS'), t1.status = t2.status,t1.cmuser_id = t2.cmuser_id, t1.cmcuserid_no = t2.cmcuserid_no,t1.user_name = t2.user_name, t1.userext1 = t2.userext1, t1.userext2 = t2.userext2, t1.userext3 = t2.userext3
6 回复

强制查询是为了啥?查询模式就只读了

sql.forceExecQuery();

这是啥操作,直接拼sql呀?不怕注入呀?

gotSql().toString()

如果删掉,会报这句

2019-11-14 10:52:41,294 org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:82) INFO  - Can't identify SQL type :   merge into TXZH_ALL t1 using (select '333333' user_id,'0401' systemid,'20191012110400' updatetime,'1' status,'adsfgdfgsf' cmuser_id,'cmcuseridno11' cmcuserid_no,'张三2' user_name,'' userext1,'' userext2,'' userext3 from dual) t2 on (t1.user_id = t2.user_id and t1.systemid = t2.systemid) when not matched then insert values (SEQ_TXZH_ALLID.nextval,TO_DATE(t2.updatetime,'YYYY-MM-DD HH24:MI:SS'),t2.status,t2.cmuser_id,t2.cmcuserid_no,t2.user_id,t2.user_name,t2.userext1,t2.userext2,t2.userext3,t2.systemid) when matched then update set t1.updatetime = TO_DATE(t2.updatetime,'YYYY-MM-DD HH24:MI:SS'), t1.status = t2.status,t1.cmuser_id = t2.cmuser_id, t1.cmcuserid_no = t2.cmcuserid_no,t1.user_name = t2.user_name, t1.userext1 = t2.userext1, t1.userext2 = t2.userext2, t1.userext3 = t2.userext3

这个就是生成sql的,一开始是拼接的,后来就改成format了

提示而已, 又没啥影响

另外, 说不更新的, 最常见的原因就是连错数据库

找到原因了,是上一任写了个拦截器,我没注意到,所以走进回滚里了~谢谢

添加回复
请先登陆
回到顶部