Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Reservation;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- import java.sql.Connection;
- import java.util.ResourceBundle;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- /**
- *
- * @author user
- */
- public class DBLayer {
- private String driver;
- private String url;
- private String password;
- private String user;
- private Connection conn;
- public DBLayer(String driver, String url, String password, String user) {
- this.driver = driver;
- this.url = url;
- this.password = password;
- this.user = user;
- }
- public DBLayer(){
- ResourceBundle sql = ResourceBundle.getBundle("Reservation.information");
- this.url = sql.getString("url");
- this.user = sql.getString("user");
- this.password = sql.getString("password");
- this.driver = sql.getString("driver");
- }
- public void connect() {
- try {
- Class.forName(driver);
- conn = DriverManager.getConnection(url, user, password);
- } catch(Exception ex) {
- ex.printStackTrace();
- }
- }
- public void close() {
- try {
- if(conn != null) conn.close();
- } catch(Exception ex) {
- ex.printStackTrace();
- }
- }
- public PreparedStatement getPreparedStatement(String sql) {
- if(conn == null) return null;
- try {
- return conn.prepareStatement(sql);
- } catch(SQLException ex) {
- ex.printStackTrace();
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement