コード例 #1
0
 public static void update() {
   String sql = "UPDATE item SET i_stock = ? WHERE i_id = ?";
   Connection conn = null;
   if (flag) {
     conn = IMDGHelper.getConnection();
   } else {
     conn = DBHelper.getConnection();
   }
   try {
     PreparedStatement pst = conn.prepareStatement(sql);
     Random random = new Random(System.currentTimeMillis());
     int count = 1000;
     int range = 100000;
     long start = System.currentTimeMillis();
     for (int i = 0; i < count; i++) {
       pst.setInt(1, random.nextInt(range) + 1);
       pst.setInt(2, random.nextInt(range) + 1);
       pst.executeUpdate();
     }
     long end = System.currentTimeMillis();
     System.out.println("update time : " + (end - start) + " ms");
     pst.close();
     conn.close();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
コード例 #2
0
 public static void valueQuery() {
   String sql = "SELECT * FROM order_line, item WHERE ol_o_id = ? AND ol_i_id = i_id";
   Connection conn = null;
   if (flag) {
     conn = IMDGHelper.getConnection();
   } else {
     conn = DBHelper.getConnection();
   }
   try {
     PreparedStatement pst = conn.prepareStatement(sql);
     ResultSet rs = null;
     Random random = new Random(System.currentTimeMillis());
     int count = 1000;
     int range = 10000;
     long start = System.currentTimeMillis();
     for (int i = 0; i < count; i++) {
       pst.setInt(1, random.nextInt(range) + 1);
       rs = pst.executeQuery();
     }
     long end = System.currentTimeMillis();
     System.out.println("valueQuery time : " + (end - start) + " ms");
     rs.close();
     pst.close();
     conn.close();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
コード例 #3
0
 public static void insertBatch() {
   String sql =
       "INSERT into order_line (ol_id, ol_o_id, ol_i_id, ol_qty, ol_discount, ol_comments) VALUES (?, ?, ?, ?, ?, ?)";
   Connection conn = null;
   if (flag) {
     conn = IMDGHelper.getConnection();
   } else {
     conn = DBHelper.getConnection();
   }
   try {
     PreparedStatement pst = conn.prepareStatement(sql);
     Random random = new Random(System.currentTimeMillis());
     int count = 1000;
     int range = 10000;
     long start = System.currentTimeMillis();
     for (int i = 0; i < count; i++) {
       pst.setInt(1, random.nextInt(range) + 2000);
       pst.setInt(2, random.nextInt(range) + 2000);
       pst.setInt(3, random.nextInt(range) + 2000);
       pst.setInt(4, random.nextInt(range) + 2000);
       pst.setDouble(5, (double) getRandomInt(0, 30) / 100);
       pst.setString(6, getRandomAString(20, 100));
       pst.addBatch();
     }
     pst.executeBatch();
     pst.clearBatch();
     long end = System.currentTimeMillis();
     System.out.println("INSERT time : " + (end - start));
     pst.close();
     conn.close();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }