标签:style blog io ar color 使用 sp on 数据
1 try { 2 boolean auto = conn.getAutoCommit(); 3 conn.setAutoCommit(false); 4 5 Statement stat = conn.createStatement(); 6 Iterator<String> it = sourcetime.iterator(); 7 // System.out.println("get sourcetime iterator successfully"); 8 while (it.hasNext()) { 9 String st = it.next(); 10 //System.out.println("this st*_*"+st+"*_*"); 11 Pattern subpat = Pattern.compile("[|]"); // 创建Pattern实例 12 String mac_time[] = subpat.split(st); 13 int time = Integer.parseInt(mac_time[1]); // time 14 String mac = mac_time[0]; 15 // System.out.println("this::::"+mac+","+gname +","+time); 16 String sql = "insert into edges (source,target,time) values(‘" + mac + "‘,‘" + gname 17 + "‘,‘" + time + "‘)"; 18 stat.addBatch(sql); 19 } 20 stat.executeBatch(); 21 conn.commit(); 22 logger.info("insert "+gname+" data into DB edges finished"); 23 conn.setAutoCommit(auto); 24 } catch (SQLException e2) { 25 // TODO Auto-generated catch block 26 e2.printStackTrace(); 27 }
使用Statement 的addBatch方法批量导入数据库
标签:style blog io ar color 使用 sp on 数据
原文地址:http://www.cnblogs.com/ivywenyuan/p/4148541.html