Advertisement
Guest User

Untitled

a guest
Oct 26th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. package com.store.model.dao;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. import org.springframework.stereotype.Component;
  8.  
  9. @Component
  10. public class DBManager {
  11.  
  12.  
  13. final String DB_IP = "127.0.0.1";
  14. final String DB_PORT = "3306";
  15. final String DB_DBNAME = "pizza_store";
  16. final String DB_USER = "root";
  17. final String DB_PASS = "1234";
  18.  
  19. private Connection con;
  20.  
  21. private DBManager() {
  22. System.out.println("hi");
  23. try {
  24. Class.forName("com.mysql.jdbc.Driver");
  25. } catch (ClassNotFoundException e) {
  26. System.out.println("Driver not found or failed to load. Check your libraries");
  27. }
  28.  
  29. try {
  30. con = DriverManager.getConnection("jdbc:mysql://" + DB_IP + ":" + DB_PORT + "/" + DB_DBNAME, DB_USER,
  31. DB_PASS);
  32. } catch (SQLException e) {
  33. System.out.println("Ops");
  34. }
  35.  
  36. }
  37.  
  38.  
  39. public Connection getConnection() {
  40. return con;
  41. }
  42.  
  43. public void closeConnection() {
  44. if (con != null) {
  45. try {
  46. con.close();
  47. } catch (SQLException e) {
  48. e.printStackTrace();
  49. }
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement