Advertisement
Guest User

Untitled

a guest
Apr 28th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. package Reservation;
  2.  
  3. /*
  4. * To change this license header, choose License Headers in Project Properties.
  5. * To change this template file, choose Tools | Templates
  6. * and open the template in the editor.
  7. */
  8.  
  9.  
  10. import java.sql.Connection;
  11. import java.util.ResourceBundle;
  12. import java.sql.DriverManager;
  13. import java.sql.PreparedStatement;
  14. import java.sql.SQLException;
  15. /**
  16. *
  17. * @author user
  18. */
  19. public class DBLayer {
  20. private String driver;
  21. private String url;
  22. private String password;
  23. private String user;
  24. private Connection conn;
  25.  
  26. public DBLayer(String driver, String url, String password, String user) {
  27. this.driver = driver;
  28. this.url = url;
  29. this.password = password;
  30. this.user = user;
  31. }
  32.  
  33. public DBLayer(){
  34. ResourceBundle sql = ResourceBundle.getBundle("Reservation.information");
  35. this.url = sql.getString("url");
  36. this.user = sql.getString("user");
  37. this.password = sql.getString("password");
  38. this.driver = sql.getString("driver");
  39. }
  40.  
  41. public void connect() {
  42. try {
  43. Class.forName(driver);
  44. conn = DriverManager.getConnection(url, user, password);
  45. } catch(Exception ex) {
  46. ex.printStackTrace();
  47. }
  48. }
  49.  
  50. public void close() {
  51. try {
  52. if(conn != null) conn.close();
  53. } catch(Exception ex) {
  54. ex.printStackTrace();
  55. }
  56. }
  57.  
  58. public PreparedStatement getPreparedStatement(String sql) {
  59. if(conn == null) return null;
  60. try {
  61. return conn.prepareStatement(sql);
  62. } catch(SQLException ex) {
  63. ex.printStackTrace();
  64. }
  65. return null;
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement