Advertisement
Guest User

CPS4Layer

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