Advertisement
Guest User

Untitled

a guest
Mar 31st, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. package server.util.sql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.util.Properties;
  7.  
  8. public class SQLHandler {
  9.  
  10. private static final String DB = "edenpsc1_db";
  11. private static final String URL = "http://eden-ps.com";
  12. private static final String USER = "edenpsc1_db";
  13. private static final String PASS = "xzfc2fWDW@e9";
  14. private static final Properties prop;
  15.  
  16. static {
  17. prop = new Properties();
  18. prop.put("user", USER);
  19. prop.put("pass", PASS);
  20. }
  21.  
  22. public static Connection conn = null;
  23.  
  24. /**
  25. * Connects to the database
  26. */
  27. public static void connect() {
  28. try {
  29. Class.forName("com.mysql.jdbc.Driver");
  30. conn = DriverManager.getConnection("jdbc:mysql://" + URL + "/" + DB, prop);
  31. System.out.println("Connected to the sql system.");
  32. } catch (Exception e) {
  33. System.out.println("Setting sql connecting to false to help not cause anymore errors.");
  34. }
  35. }
  36.  
  37. public static Connection getConnection() {
  38. try {
  39. if (conn == null || conn.isClosed()) {
  40. conn = DriverManager.getConnection("jdbc:mysql://" + URL + "/"
  41. + DB, prop);
  42. }
  43. } catch (SQLException e) {
  44. System.out.println(e);
  45. e.printStackTrace();
  46. }
  47. return conn;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement