Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.util.Properties;
- import java.util.Random;
- import com.ibm.db2.*;
- public class main {
- /**
- * @param args
- */
- public static String randomSTr(){
- char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
- StringBuilder sb = new StringBuilder();
- Random random = new Random();
- for (int i = 0; i < 20; i++) {
- char c = chars[random.nextInt(chars.length)];
- sb.append(c);
- }
- return sb.toString();
- }
- public static void main(String[] args) {
- try {
- Properties properties = new java.util.Properties();
- // Create Properties object
- properties.put("user", "db2admin"); // Set user ID for the connection
- properties.put("password", "db2admin"); // Set password for the connection
- Class.forName("com.ibm.db2.jcc.DB2Driver");
- String url = "jdbc:db2:mydb";
- // Set URL for the data source
- Connection con = DriverManager.getConnection(url, properties);
- // Create connection
- Statement stmt = con.createStatement();
- Random rnd = new Random();
- long time = System.nanoTime();
- for(int i=0;i<100;i++){
- stmt.execute("SELECT * FROM users_zip");
- //}
- /*int age = rnd.nextInt(100);
- String name = randomSTr();
- String surname = randomSTr();
- String sql = "INSERT into users_zip(id, name, surname, age) VALUES (" + i + ", '"+ name +"','"+ surname + "', " + age + ")";
- stmt.execute(sql);*/
- }
- time = System.nanoTime() - time;
- System.out.println("TIME: " + time);
- con.close();
- }
- catch (Exception e) {
- System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement