Guest User

Untitled

a guest
Feb 13th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. package postgrestest;
  2.  
  3. import java.sql.*;
  4.  
  5. public class IncompleteTransvanilla implements Runnable {
  6. private int seq = 0;
  7. private Connection connection = null;
  8. private boolean insertoperation = true;
  9.  
  10. public static void main(String[] args) throws Exception{
  11. boolean flag = true;
  12. if(args.length>0) {flag = false;}
  13. for(int i=0;i<10;i++) {
  14. new Thread(new IncompleteTransvanilla(i,flag)).start();
  15. //Thread.sleep(1000*(int)(Math.random()*10));
  16. }
  17. Thread.sleep(10000);
  18. }
  19.  
  20. public IncompleteTransvanilla(int i, boolean flag) {
  21. try {
  22. connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/testdb", "postgres", "postgres");
  23. connection.setAutoCommit(false);
  24. } catch (Exception e) {
  25. System.out.println("error");
  26. }
  27. seq=i;
  28. insertoperation = flag;
  29. }
  30.  
  31. public void run() {
  32. try {
  33. PreparedStatement statement;
  34. if(insertoperation == true) {
  35. System.out.println("Inserting");
  36. statement = connection.prepareStatement("Insert into uacc(user_id,username,password,email) values(DEFAULT,?,'samplepass','samplemail')");
  37. }
  38. else {
  39. System.out.println("Updating");
  40. statement = connection.prepareStatement("update uacc set username=? where user_id=1");
  41. }
  42. int maxval = 100;
  43. for(int i=0;i<maxval;i++) {
  44. statement.setString(1, "sampleuser"+((seq*maxval)+i));
  45. statement.execute();
  46. }
  47. Thread.sleep(10000);
  48. connection.commit();
  49. } catch (Exception e) {
  50. System.out.println("Connection failure.");
  51. }
  52. }
  53.  
  54. }
Add Comment
Please, Sign In to add comment