Guest User

Untitled

a guest
Nov 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class Database {
  4. private String jdbcDriver = "com.mysql.jdbc.Driver";
  5. private String dbUrl = "jdbc:mysql://localhost/?user=root&password=lnmiit&useSSL=false";
  6. private String useDBStatement = "Use Employees";
  7. private String createTable1 = "CREATE TABLE IF NOT EXISTS Employee" +
  8. "(id int(10) PRIMARY KEY AUTO_INCREMENT NOT NULL, " +
  9. "name varchar(30) NOT NULL, " +
  10. "medical_leaves_remaining int(10) NOT NULL, " +
  11. "casual_leaves_remaining int(10) NOT NULL" +
  12. ")";
  13. private String createTable2 = "CREATE TABLE IF NOT EXISTS LeaveDates(" +
  14. "id int(10) NOT NULL," +
  15. "type varchar(10) NOT NULL," +
  16. "dates varchar(30) NOT NULL" +
  17. ")";
  18. private Connection connection;
  19.  
  20. Database(){
  21. try {
  22. Class.forName(jdbcDriver);
  23. connection = DriverManager.getConnection(dbUrl);
  24. System.out.println("Connected!");
  25. Statement st = connection.createStatement();
  26. st.executeUpdate(useDBStatement);
  27. // System.out.println(createTable);
  28. st.executeUpdate(createTable1);
  29. st.executeUpdate(createTable2);
  30. } catch (ClassNotFoundException e) {
  31. e.printStackTrace();
  32. } catch (SQLException e) {
  33. e.printStackTrace();
  34. }
  35. }
  36.  
  37. public Connection getConnection() {
  38. return connection;
  39. }
  40.  
  41. }
Add Comment
Please, Sign In to add comment