Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package solve;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- public class solve {
- static int getRandom(int x) {
- return (int) Math.random()*x;
- }
- static char getRandomChar() {
- int x = getRandom(3);
- if(x == 0) return (char) ( getRandom(26) + 'a');
- if(x == 1) return (char) ( getRandom(26) + 'A');
- return (char) (getRandom(10) + '0');
- }
- static String getRandomString(int x) {
- StringBuilder ret = new StringBuilder("\'");
- for(int i=0; i < x ; ++i)
- ret.append(getRandomChar());
- ret.append('\'');
- return ret.toString();
- }
- static String getRandomeDate() {
- return getRandom(30) + "/" + getRandom(12) + "/" + getRandom(100000);
- }
- public static void main (String [] args) throws Exception {
- // ArrayList<String> book, book_author, publisher, book_copies, book_loans, borrower, libarary_branch;
- // book = new ArrayList<String>();
- // book_author = ;
- // publisher = ;
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","SAMPLE","admin");
- java.sql.Statement stmt = con.createStatement();
- ResultSet myRs = stmt.executeQuery("select * from book");
- // 4. Process the result set
- while (myRs.next())
- System.out.println(myRs.getString("book_id") + ", " + myRs.getString("title") + ", " + myRs.getString("publishername"));
- for(int i = 0; i < 200000; ++i) {
- String book_id = getRandomString(5);
- String author_name = getRandomString(10);
- String title = getRandomString(10);
- String publisher_name = getRandomString(10);
- // book.pb(book_id + ',' + title + ',' + publisher_name);
- // book_author.pb(book_id + ',' + author_name);
- String pAddress = getRandomString(10);
- String phone = getRandomString(10);
- String insert = "INSERT INTO publisher VALUES (" + publisher_name + "," + pAddress + "," + phone + ")";
- stmt.executeUpdate(insert);
- // publisher.pb(publisher_name + ',' + pAddress + ',' + phone);
- insert = "INSERT INTO book VALUES (" + book_id + "," + title + "," + publisher_name + ")";
- stmt.executeUpdate(insert);
- insert = "INSERT INTO book_id VALUES (" + book_id + "," + author_name + ")";
- stmt.executeUpdate(insert);
- String branch_id = getRandomString(10);
- insert = "INSERT INTO library_branch VALUES (" + branch_id + ","
- + getRandomString(10) + "," + getRandomString(10) + ")";
- stmt.executeUpdate(insert);
- String card_no = getRandomString(5);
- insert = "INSERT INTO borrower VALUES (" + card_no + ',' +
- getRandomString(10) + ',' + getRandomString(10) + ',' + getRandomString(10) + ")";
- stmt.executeUpdate(insert);
- // libarary_branch.pb(branch_id + ',' + getRandomString(10) + ',' + getRandomString(10));
- // borrower.pb(card_no + ',' + getRandomString(10) + ',' + getRandomString(10) + ',' + getRandomString(10));
- insert = "INSERT INTO book_id VALUES (" + book_id + ',' + branch_id + ',' + getRandom(100) + ")";
- stmt.executeUpdate(insert);
- // book_copies.pb(book_id + ',' + branch_id + ',' + getRandom(100));
- insert = "INSERT INTO book_id VALUES (" + book_id + ',' + branch_id
- + ',' + card_no + ',' + getRandomeDate() + ',' + getRandomeDate() + ")";
- stmt.executeUpdate(insert);
- // book_loans.pb(book_id + ',' + branch_id + ',' + card_no + ',' + getRandomeDate() + ',' + getRandomeDate());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement