Advertisement
Guest User

Untitled

a guest
May 11th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. package database;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.util.Properties;
  7.  
  8. import logging.LogType;
  9. import logging.SLog;
  10.  
  11. import config.SProperties;
  12.  
  13. public class UserDatabase {
  14. private static final Properties properties = SProperties.getProperties();
  15.  
  16. private static final String host = properties.getProperty("DBHost");
  17. private static final String port = properties.getProperty("DBPort");
  18. private static final String database = properties.getProperty("DBDatabase");
  19. private static final String username = properties.getProperty("DBUsername");
  20. private static final String password = properties.getProperty("DBPassword");
  21.  
  22. public synchronized static Connection getInstance() {
  23.  
  24. Connection conn = null;
  25. try {
  26. Class.forName("com.mysql.jdbc.Driver");
  27. if (conn == null)
  28. conn = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
  29. } catch (final ClassNotFoundException e) {
  30. SLog.Entry(LogType.Halt, "The MYSQL Connection driver could not be loaded!");
  31. e.printStackTrace();
  32. System.exit(1);
  33. } catch (final SQLException e) {
  34. SLog.Entry(LogType.Halt, "Some error occured while creating a database connection.");
  35. e.printStackTrace();
  36. System.exit(1);
  37. }
  38. return conn;
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement