今天用jdbc on duplicate key update 做批量更新时候一直不成功,但是同样的sql语句在mysql的客户端工具以及命令行都能执行成功。情况大致如下// id:主键 reprints:转发数 comments:评论数
// 数据库还有一个标题字段:title varchar(255) NOT NULL// 目的id为:2245845和2245846的两天数据在数据库中已经存在,现在想要更新 reprints和comments 值分别为:(2245845,3,2),(2245846,4,1)insert into records (id,reprints,comments) values (2245845,3,2),(2245846,4,1) on duplicate key update reprints = values(reprints),comments = values(comments);该语句在客户端工具以及命令行都能执行成功,但是通过jdbc执行时报错:Field 'title' doesn't have a default valuejdbc操作如下:
Statement stat = connection.createStatement();
String sql = "insert into records (id,reprints,comments) values (2245845,3,2),(2245846,4,1) on duplicate key update reprints = values(reprints),comments = values(comments);";
stat.execute(sql);请各位大侠帮忙看看。
// 数据库还有一个标题字段:title varchar(255) NOT NULL// 目的id为:2245845和2245846的两天数据在数据库中已经存在,现在想要更新 reprints和comments 值分别为:(2245845,3,2),(2245846,4,1)insert into records (id,reprints,comments) values (2245845,3,2),(2245846,4,1) on duplicate key update reprints = values(reprints),comments = values(comments);该语句在客户端工具以及命令行都能执行成功,但是通过jdbc执行时报错:Field 'title' doesn't have a default valuejdbc操作如下:
Statement stat = connection.createStatement();
String sql = "insert into records (id,reprints,comments) values (2245845,3,2),(2245846,4,1) on duplicate key update reprints = values(reprints),comments = values(comments);";
stat.execute(sql);请各位大侠帮忙看看。
解决方案 »
- 看技术书的时候你们有没有这种感觉。
- 高手请进
- 请教hashmap两个map匹配
- serialVersionUID是做什么用的
- 跪问strust1和strust2先学哪个?
- cmp 数据更新,删除问题
- Hibernate 使用 ehcache 缓存时,many-to-one 中的one为空
- 我是个刚要毕业的大专生计算机专业的不知道何去何从
- 如何写自己的java API?
- 在struts 的action 中我怎么使用mapping.findforward后new ActionForward()来是我的return的jsp界面在新的一业中显示啊????????急!!!!看
- 如何拦截final类方法?求解
- svn win2000 安装。 求方法
定义为not null,所以你的title必须赋值
但是insert语句没有给这个字段赋值
我执行的目的是更新数据并不是插入,title字段的值已经存在了。