Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package postgrestest;
- import java.sql.*;
- public class IncompleteTransvanilla implements Runnable {
- private int seq = 0;
- private Connection connection = null;
- private boolean insertoperation = true;
- public static void main(String[] args) throws Exception{
- boolean flag = true;
- if(args.length>0) {flag = false;}
- for(int i=0;i<10;i++) {
- new Thread(new IncompleteTransvanilla(i,flag)).start();
- //Thread.sleep(1000*(int)(Math.random()*10));
- }
- Thread.sleep(10000);
- }
- public IncompleteTransvanilla(int i, boolean flag) {
- try {
- connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/testdb", "postgres", "postgres");
- connection.setAutoCommit(false);
- } catch (Exception e) {
- System.out.println("error");
- }
- seq=i;
- insertoperation = flag;
- }
- public void run() {
- try {
- PreparedStatement statement;
- if(insertoperation == true) {
- System.out.println("Inserting");
- statement = connection.prepareStatement("Insert into uacc(user_id,username,password,email) values(DEFAULT,?,'samplepass','samplemail')");
- }
- else {
- System.out.println("Updating");
- statement = connection.prepareStatement("update uacc set username=? where user_id=1");
- }
- int maxval = 100;
- for(int i=0;i<maxval;i++) {
- statement.setString(1, "sampleuser"+((seq*maxval)+i));
- statement.execute();
- }
- Thread.sleep(10000);
- connection.commit();
- } catch (Exception e) {
- System.out.println("Connection failure.");
- }
- }
- }
Add Comment
Please, Sign In to add comment