Guest User

Untitled

a guest
Jul 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. /**
  2. *
  3. */
  4. package com.kittyirc.io;
  5.  
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.util.logging.Logger;
  9.  
  10. import com.kittyirc.Constants;
  11.  
  12. /**
  13. * @author Michael
  14. *
  15. */
  16. public class SqlConnector {
  17.  
  18. private static final Logger logger = Logger.getLogger(SqlConnector.class
  19. .getName());
  20.  
  21. private static final SqlConnector INSTANCE = new SqlConnector();
  22.  
  23. private Connection connection;
  24.  
  25. private SqlConnector() {
  26. try {
  27. Class.forName("com.mysql.jdbc.Driver").newInstance();
  28. connection = DriverManager.getConnection("jdbc:mysql://"
  29. + Constants.SQL_IP + "/" + Constants.SQL_DB,
  30. Constants.SQL_USER, Constants.SQL_PASS);
  31. logger.info("Connected to " + Constants.SQL_IP + " : "
  32. + Constants.SQL_DB + " .");
  33. } catch (Exception e) {
  34. logger.severe("SQL Cannot connect to specified database.");
  35. e.printStackTrace();
  36. System.exit(0);
  37. }
  38. }
  39.  
  40. public static SqlConnector getSqlConnector() {
  41. return INSTANCE;
  42. }
  43.  
  44. /**
  45. * @return the connection
  46. */
  47. public Connection getConnection() {
  48. return connection;
  49. }
  50.  
  51. }
Add Comment
Please, Sign In to add comment