NutzCN Logo
问答 更新多条数据的问题。不知道应该怎么处理
发布于 1715天前 作者 wx_p064hjeoh9l2g0cqspro 1261 次浏览 复制 上一个帖子 下一个帖子
标签:

各位大哥。我现在有个产品排序的需求。要求是:顺序为8的产品,将其顺序改为2,则原2-7位产品顺序依次+1。但是我调用方法就报错!不知道是方法错了还是思路错了。请各位大哥帮帮忙啊!!!!下面是代码

dao.update(Product.class, Chain.makeSpecial("product_sort", "+1"),Cnd.where("product_sort", ">", product.getProductSort()));
8 回复

现在这两种方法都报错。。

        int update = dao.update(Product.class, Chain.makeSpecial("product_sort", "+1").add("location", "yvr"), Cnd.where("product_sort", ">", "1"));

报错信息如下:

Exception in thread "main" org.nutz.dao.DaoException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'location' in 'field list'

字段名错了嘛

没有错啊大哥。这个是我的字段名

product_sort
int update = dao.update(Product.class, Chain.makeSpecial("product_sort", "+1"), Cnd.where("product_sort", ">", 1));

我现在运行这段代码他给我报的是这个错误。好像是说有3条记录他不知道往哪个上添加。。。。

Exception in thread "main" org.nutz.dao.DaoException: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '3' for key 'product_sort'

大哥我按你说的改了一下代码:

        int update = dao.update(Product.class, Chain.makeSpecial("product_sort", "+1").add("product_sort", "int"), Cnd.where("product_sort", ">", "1"));

但是又新报了一个错误:我数据库的字段类型也是int啊。。。。

Exception in thread "main" org.nutz.dao.DaoException: java.sql.SQLException: Incorrect integer value: 'int' for column 'product_sort' at row 1

product_sort值类型不对

大哥我的实体类中的值是Integer。数据库表字段中的值是int。我现在是真懵逼了!

睁大你的眼睛看看自己写了啥

.add("product_sort", "int")

product_sort的值是字符串 "int" ???

int update = dao.update(Product.class, Chain.makeSpecial("product_sort", "+1"), Cnd.where("product_sort", ">", 1));

大哥我现在懵逼了。我实体类,表,传递过来的参数都是int类型的。怎么到这个方法中就变成Sting了呢?我要是在这写成int或者Integer直接就报错了。

            dao.update(Product.class, Chain.makeSpecial("product_sort", "+1").add("product_sort", int), Cnd.where("product_sort", ">", product.getProductSort()));

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