1 Connection conn = null; 2 PreparedStatement stmt = null; 3 try{ 4 conn = JdbcUtil.getConnection(); 5 stmt = conn.prepareStatement("insert into t1 (id,name) values(?,?)"); 6 7 for(int i=0;i<10;i++){ 8 stmt.setInt(1, i+1); 9 stmt.setString(2, "aa"+(i+1)); 10 stmt.addBatch();//向缓存中加的参数 11 } 12 13 int [] ii = stmt.executeBatch();//批处理.每条语句影响的行数 14 15 for(int i:ii) 16 System.out.println(i); 17 }catch(Exception e){ 18 e.printStackTrace(); 19 }finally{ 20 JdbcUtil.release(null, stmt, conn); 21 }
时间: 2024-10-06 22:43:20