Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class Database {
- private String jdbcDriver = "com.mysql.jdbc.Driver";
- private String dbUrl = "jdbc:mysql://localhost/?user=root&password=lnmiit&useSSL=false";
- private String useDBStatement = "Use Employees";
- private String createTable1 = "CREATE TABLE IF NOT EXISTS Employee" +
- "(id int(10) PRIMARY KEY AUTO_INCREMENT NOT NULL, " +
- "name varchar(30) NOT NULL, " +
- "medical_leaves_remaining int(10) NOT NULL, " +
- "casual_leaves_remaining int(10) NOT NULL" +
- ")";
- private String createTable2 = "CREATE TABLE IF NOT EXISTS LeaveDates(" +
- "id int(10) NOT NULL," +
- "type varchar(10) NOT NULL," +
- "dates varchar(30) NOT NULL" +
- ")";
- private Connection connection;
- Database(){
- try {
- Class.forName(jdbcDriver);
- connection = DriverManager.getConnection(dbUrl);
- System.out.println("Connected!");
- Statement st = connection.createStatement();
- st.executeUpdate(useDBStatement);
- // System.out.println(createTable);
- st.executeUpdate(createTable1);
- st.executeUpdate(createTable2);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public Connection getConnection() {
- return connection;
- }
- }
Add Comment
Please, Sign In to add comment