为什么一直跳主键报错 299999是最大值吗?主键是没数据的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | package com.imooc.jdbc.sample; import com.imooc.jdbc.hrapp.common.DbUtils; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Date; public class BatchSample { private static void tc1(){ Connection conn = null ; PreparedStatement pstmt = null ; int num= 0 ; try { long startTime = new Date().getTime(); conn = DbUtils.getConnection(); conn.setAutoCommit( false ); String sql = "insert into employee(eno,ename,salary,dname) values(?,?,?,?)" ; for ( int i = 100000 ;i < 200000 ;i ++){ pstmt = conn.prepareStatement(sql); pstmt.setInt( 1 ,i); pstmt.setString( 2 , "员工" +i); pstmt.setFloat( 3 ,4000f); pstmt.setString( 4 , "市场部" ); num = pstmt.executeUpdate()+num; } if (num != 0 ){ System.out.println( "成功" +num); } else { System.out.println( "失败" +num); } conn.commit(); long endTime = new Date().getTime(); System.out.println(endTime-startTime); } catch (Exception e) { e.printStackTrace(); try { if (conn != null && !conn.isClosed()){ conn.rollback(); } } catch (SQLException ex) { e.printStackTrace(); } } finally { DbUtils.closeConnection( null ,pstmt,conn); } } private static void tc2(){ Connection conn = null ; PreparedStatement pstmt = null ; int num= 0 ; try { long startTime = new Date().getTime(); conn = DbUtils.getConnection(); conn.setAutoCommit( false ); String sql = "insert into employee(eno,ename,salary,dname) values(?,?,?,?)" ; for ( int i = 200000 ;i < 300000 ;i ++){ pstmt = conn.prepareStatement(sql); pstmt.setInt( 1 ,i); pstmt.setString( 2 , "员工" +i); pstmt.setFloat( 3 ,4000f); pstmt.setString( 4 , "市场部" ); num = pstmt.executeUpdate()+num; pstmt.addBatch(); } if (num != 0 ){ System.out.println( "成功" +num); } else { System.out.println( "失败" +num); } pstmt.executeBatch(); conn.commit(); long endTime = new Date().getTime(); System.out.println(endTime-startTime); } catch (Exception e) { e.printStackTrace(); try { if (conn != null && !conn.isClosed()){ conn.rollback(); } } catch (SQLException ex) { e.printStackTrace(); } } finally { DbUtils.closeConnection( null ,pstmt,conn); } } public static void main(String[] args) { tc1(); tc2(); } } |
4
收起
正在回答 回答被采纳积分+1
Java工程师 2024版
- 参与学习 2035 人
- 提交作业 1391 份
- 解答问题 1258 个
2024重磅革新,超百小时内容豪华升级,加速提升高级技能与高薪就业竞争力 课程紧贴企业最新人才需求,历经7年持续迭代,帮助万名学子入行转行 从零起点到高阶实战,学习路径稳健顺滑,成就从小白到工程师高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧