- public static void insert() {
-
- Long begin = new Date().getTime();
-
- String prefix = "INSERT INTO tb_big_data (count, create_time, random) VALUES ";
- try {
-
- StringBuffer suffix = new StringBuffer();
-
- conn.setAutoCommit(false);
-
-
- PreparedStatement pst = conn.prepareStatement("");
-
- for (int i = 1; i <= 100; i++) {
-
- for (int j = 1; j <= 10000; j++) {
-
- suffix.append("(" + j * i + ", SYSDATE(), " + i * j
- * Math.random() + "),");
- }
-
- String sql = prefix + suffix.substring(0, suffix.length() - 1);
-
- pst.addBatch(sql);
-
- pst.executeBatch();
-
- conn.commit();
-
- suffix = new StringBuffer();
- }
-
- pst.close();
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
-
- Long end = new Date().getTime();
-
- System.out.println("cast : " + (end - begin) / 1000 + " ms");
- }
posted on
2016-12-26 22:02
guols
阅读(
129)
评论()
编辑
收藏
举报