NutzCN Logo
问答 update 一个集合如何添加where 条件??
发布于 2451天前 作者 qq_6f5e9a61 1824 次浏览 复制 上一个帖子 下一个帖子
标签:

update map集合怎么添加where条件?update是不是只是更新map集合中自己添加的字段呢?

10 回复

update(map, cnd) ??

map.put(".table","user");
 map.put("name","tom");
dao.update(map, Cnd.where("id","=",1));

Exception in thread "main" org.nutz.dao.DaoException: !Nutz SQL Error: 'UPDATE user SET name='tom'   AND  (id1=1)'
PreparedStatement: 
'UPDATE user SET name=?   AND  (id1=?)'
CaseMessage=Data truncation: Truncated incorrect DOUBLE value: 'tom'

请问这么不对吗?

贴完整报错信息

18-03-08 10:58:09.985 DEBUG [main] UPDATE user SET name=?   AND  (name=?)
    |   1 | 2 |
    |-----|---|
    | tom | 1 |
  For example:> "UPDATE user SET name='tom'   AND  (name=1)"
18-03-08 10:58:09.994 DEBUG [main] SQLException
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'tom'
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3968)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
	at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:308)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:90)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:125)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:252)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:55)
	at org.nutz.dao.impl.NutDao.update(NutDao.java:318)
	at nutz.TestUpdate.main(TestUpdate.java:31)
Exception in thread "main" org.nutz.dao.DaoException: !Nutz SQL Error: 'UPDATE user SET name='tom'   AND  (name=1)'
PreparedStatement: 
'UPDATE user SET name=?   AND  (name=?)'
CaseMessage=Data truncation: Truncated incorrect DOUBLE value: 'tom'
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:104)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:125)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:252)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:55)
	at org.nutz.dao.impl.NutDao.update(NutDao.java:318)
	at nutz.TestUpdate.main(TestUpdate.java:31)
Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'tom'
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3968)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
	at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:308)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:90)
	... 13 more

AND (name=?) 应该是 AND (id=?) 日志贴错了

dao.update("user", Chain.make("name", "tome"), Cnd.where("id","=",1));

如果一共有200个字段 ,需要更新其中150个,这么写是不是太麻烦了。能直接更新map吗,在map中添加需要更新的150个字段

可以Chain.from

dao.update("user", Chain.from(map), Cnd.where("id","=",1));

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