Advertisement
m4ly

SBD lab2

Oct 25th, 2014
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.Properties;
  3. import java.util.Random;
  4.  
  5. import com.ibm.db2.*;
  6. public class main {
  7.  
  8.    
  9.     /**
  10.      * @param args
  11.      */
  12.     public static String randomSTr(){
  13.         char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
  14.         StringBuilder sb = new StringBuilder();
  15.         Random random = new Random();
  16.         for (int i = 0; i < 20; i++) {
  17.             char c = chars[random.nextInt(chars.length)];
  18.             sb.append(c);
  19.         }
  20.         return sb.toString();
  21.     }
  22.  
  23.    
  24.     public static void main(String[] args) {
  25.        
  26.         try {
  27.    
  28.             Properties properties = new java.util.Properties();
  29.             // Create Properties object
  30.             properties.put("user", "db2admin");         // Set user ID for the connection
  31.             properties.put("password", "db2admin");     // Set password for the connection
  32.             Class.forName("com.ibm.db2.jcc.DB2Driver");
  33.             String url = "jdbc:db2:mydb";
  34.             // Set URL for the data source
  35.             Connection con = DriverManager.getConnection(url, properties);
  36.             // Create connection
  37.             Statement stmt = con.createStatement();
  38.             Random rnd = new Random();
  39.             long time = System.nanoTime();
  40.            
  41.             for(int i=0;i<100;i++){
  42.                 stmt.execute("SELECT * FROM users_zip");
  43.             //}
  44.                 /*int age = rnd.nextInt(100);
  45.            
  46.                 String name = randomSTr();
  47.                 String surname = randomSTr();
  48.                 String sql = "INSERT into users_zip(id, name, surname, age) VALUES (" + i + ", '"+ name +"','"+ surname + "', " + age + ")";
  49.                 stmt.execute(sql);*/
  50.             }
  51.             time = System.nanoTime() - time;
  52.             System.out.println("TIME: " +  time);
  53.             con.close();
  54.         }
  55.         catch (Exception e) {
  56.          System.out.println(e);
  57.         }
  58.     }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement