没报错,没插入进去,估计你查错库了或表了。对应一下你的配置文件
求解JDBC使用批处理executeBatch()之后commit(),数据库没有变化。
5Java的JDBC使用批处理executeBatch()之后commit(),数据库没有变化。
代码
public static boolean newProblem_state(List<User_t> auditorlist, Problems_t problems)throws ClassNotFoundException, SQLException {
KrakenRecord.debug("正在建立关联"+auditorlist.size());
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
conn.setAutoCommit(false); // 设置手动提交
String sql = "insert into problemstate_ta (problemstate_problem_id,problemstate_auditor_id,problemstate_state) values("
+ problems.getProblems_id() + ",?,0)";
PreparedStatement ps = conn.prepareStatement(sql);
for (User_t user_t : auditorlist) {
ps.setInt(1, user_t.getUser_id());
ps.addBatch();// 添加到批次
}
int[] i = ps.executeBatch();// 提交批处理
conn.commit();// 执行
for (int j : i) {
System.out.println(j);
}
// 关闭资源
ps.close();
conn.close();
return true;
}
以上代码运行后,显示:
正在建立关联4
1
1
1
1
auditorlist的size是4正确,打印的四个1应该是executeBatch()正确执行了,但是数据库没有变化,求解
补充:昨晚发现是插入的数据库没反应,也就是problemstate_ta 这个表,无法插入数据,命令没有写错,在Navicat中窗口模式手动插入数据,数据的自动增长id显示+1,插入数据也没有报错,但是刷新表,数据没了,求解
- 点赞
- 写回答
- 关注问题
- 收藏
- 复制链接分享
- 邀请回答
2条回答
为你推荐
- JDBC mysql批处理 插入数据似乎遇到了条数限制,请教解决方法
- java
- mysql
- 1个回答
- 使用SpringBoot+MybatisPlus实现多表入库的时候报空指针异常
- java
- java-ee
- maven
- intellij-idea
- 2个回答
- JDBC插入大量数据问题
- jdbc
- mysql
- 0个回答
- jdbc可以支持批量查询么
- 编程语言问答
- 互联网问答
- it技术
- IT行业问题
- 计算机技术
- 0个回答
- mybatis3 mysql数据库管理系统的自动递增字段 如何获取
- mybatis
- mysql
- 0个回答
- 关于jdbc事务处理,批量插入数据的问题
- spring
- 0个回答
- executeBatch()出错后如何继续执行剩下的sql语句
- 企业应用
- 0个回答
- com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:
- 企业应用
- 0个回答
- 使用addBatch与executeBatch批量处理SQL
- dao
- 0个回答
- MySQL数据库连接问题。
- 编程语言问答
- 互联网问答
- it技术
- IT行业问题
- 计算机技术
- 0个回答
- statement批处理
- 数据库
- oracle
- 0个回答
- hibernate 入门 Could not execute JDBC batch update 能在sql数据库中创建一个表,但是不能添加数据
- hibernate
- 0个回答
- jdbc直连,连接无法关闭!
- dao
- 0个回答
- 关于数据库批处理的问题
- 企业应用
- 0个回答
- Java读取文本数据存到数据库,在方法执行完成后为啥所占用的内存资源没释放?
- 内存泄漏
- jdbc
- swing
- 3个回答
- JAVA中使用JDBC做批量处理时,没有报错,但是数据没有插入数据库
- java
- 批处理
- 2个回答
- Statement executeBatch()批量提交效率好低 求高手答疑
- executebatch
- 优化
- 数据库
- 1个回答
- 用mysql做批处理,插入一万条数据,配置了任然打不开批处理
- 2个回答
- java JDBC 批量插入的时候报数组下标越界,求大神
- jdbc
- 对象
- boolean
- 3个回答
- 提交表单到数据库报错
- java
- hibernate
- tomcat
- oracle
- 11个回答