Advertisement
Guest User

Untitled

a guest
Apr 28th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. package solve;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6.  
  7. public class solve {
  8.  
  9.  
  10. static int getRandom(int x) {
  11. return (int) Math.random()*x;
  12. }
  13.  
  14. static char getRandomChar() {
  15. int x = getRandom(3);
  16. if(x == 0) return (char) ( getRandom(26) + 'a');
  17. if(x == 1) return (char) ( getRandom(26) + 'A');
  18. return (char) (getRandom(10) + '0');
  19. }
  20.  
  21. static String getRandomString(int x) {
  22. StringBuilder ret = new StringBuilder("\'");
  23. for(int i=0; i < x ; ++i)
  24. ret.append(getRandomChar());
  25. ret.append('\'');
  26. return ret.toString();
  27. }
  28.  
  29. static String getRandomeDate() {
  30. return getRandom(30) + "/" + getRandom(12) + "/" + getRandom(100000);
  31. }
  32.  
  33.  
  34.  
  35. public static void main (String [] args) throws Exception {
  36. // ArrayList<String> book, book_author, publisher, book_copies, book_loans, borrower, libarary_branch;
  37. // book = new ArrayList<String>();
  38. // book_author = ;
  39. // publisher = ;
  40.  
  41. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","SAMPLE","admin");
  42. java.sql.Statement stmt = con.createStatement();
  43.  
  44. ResultSet myRs = stmt.executeQuery("select * from book");
  45.  
  46. // 4. Process the result set
  47. while (myRs.next())
  48. System.out.println(myRs.getString("book_id") + ", " + myRs.getString("title") + ", " + myRs.getString("publishername"));
  49.  
  50.  
  51. for(int i = 0; i < 200000; ++i) {
  52. String book_id = getRandomString(5);
  53. String author_name = getRandomString(10);
  54. String title = getRandomString(10);
  55. String publisher_name = getRandomString(10);
  56.  
  57.  
  58. // book.pb(book_id + ',' + title + ',' + publisher_name);
  59. // book_author.pb(book_id + ',' + author_name);
  60.  
  61. String pAddress = getRandomString(10);
  62. String phone = getRandomString(10);
  63.  
  64. String insert = "INSERT INTO publisher VALUES (" + publisher_name + "," + pAddress + "," + phone + ")";
  65. stmt.executeUpdate(insert);
  66.  
  67.  
  68. // publisher.pb(publisher_name + ',' + pAddress + ',' + phone);
  69.  
  70. insert = "INSERT INTO book VALUES (" + book_id + "," + title + "," + publisher_name + ")";
  71. stmt.executeUpdate(insert);
  72.  
  73. insert = "INSERT INTO book_id VALUES (" + book_id + "," + author_name + ")";
  74. stmt.executeUpdate(insert);
  75.  
  76. String branch_id = getRandomString(10);
  77.  
  78. insert = "INSERT INTO library_branch VALUES (" + branch_id + ","
  79. + getRandomString(10) + "," + getRandomString(10) + ")";
  80. stmt.executeUpdate(insert);
  81.  
  82. String card_no = getRandomString(5);
  83.  
  84. insert = "INSERT INTO borrower VALUES (" + card_no + ',' +
  85. getRandomString(10) + ',' + getRandomString(10) + ',' + getRandomString(10) + ")";
  86. stmt.executeUpdate(insert);
  87.  
  88. // libarary_branch.pb(branch_id + ',' + getRandomString(10) + ',' + getRandomString(10));
  89. // borrower.pb(card_no + ',' + getRandomString(10) + ',' + getRandomString(10) + ',' + getRandomString(10));
  90.  
  91.  
  92. insert = "INSERT INTO book_id VALUES (" + book_id + ',' + branch_id + ',' + getRandom(100) + ")";
  93. stmt.executeUpdate(insert);
  94.  
  95. // book_copies.pb(book_id + ',' + branch_id + ',' + getRandom(100));
  96.  
  97.  
  98. insert = "INSERT INTO book_id VALUES (" + book_id + ',' + branch_id
  99. + ',' + card_no + ',' + getRandomeDate() + ',' + getRandomeDate() + ")";
  100. stmt.executeUpdate(insert);
  101.  
  102. // book_loans.pb(book_id + ',' + branch_id + ',' + card_no + ',' + getRandomeDate() + ',' + getRandomeDate());
  103.  
  104. }
  105. }
  106.  
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement