Guest User

Untitled

a guest
Nov 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. package test;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class DbConnection {
  8.  
  9. private Connection dbConnection = null;
  10.  
  11. public DbConnection() {
  12. try {
  13. this.dbConnection = DriverManager.getConnection(
  14. "jdbc:mysql://localhost:3306/new_db?useSSL=false",
  15. "root",
  16. "coderslab"
  17. );
  18.  
  19. } catch(SQLException e) {
  20. e.printStackTrace();
  21. }
  22. }
  23.  
  24. public Connection getConnection() {
  25. return this.dbConnection;
  26. }
  27.  
  28. public void closeConnection() {
  29.  
  30. if(this.dbConnection != null) {
  31. try {
  32. this.dbConnection.close();
  33. } catch (SQLException e) {
  34. e.printStackTrace();
  35. }
  36. }
  37. }
  38. }
Add Comment
Please, Sign In to add comment