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 |
try { boolean auto = conn.getAutoCommit(); conn.setAutoCommit(false); Statement stat = conn.createStatement(); Iterator<String> it = sourcetime.iterator(); // System.out.println("get sourcetime iterator successfully"); while (it.hasNext()) { String st = it.next(); //System.out.println("this st*_*"+st+"*_*"); Pattern subpat = Pattern.compile("[|]"); // 创建Pattern实例 String mac_time[] = subpat.split(st); int time = Integer.parseInt(mac_time[1]); // time String mac = mac_time[0]; // System.out.println("this::::"+mac+","+gname +","+time); String sql = "insert into edges (source,target,time) values('" + mac + "','" + gname + "','" + time + "')"; stat.addBatch(sql); } stat.executeBatch(); conn.commit(); logger.info("insert "+gname+" data into DB edges finished"); conn.setAutoCommit(auto); } catch (SQLException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } |
from:https://www.cnblogs.com/ivywenyuan/p/4148541.html