Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1.  
  2. private static Connection conn = null;
  3.  
  4. public static Connection getConnection() {
  5. try {
  6. Class.forName("com.mysql.jdbc.Driver");
  7. } catch (ClassNotFoundException e) {
  8. e.printStackTrace();
  9.  
  10. }
  11. try {
  12.  
  13. if (conn == null) {
  14.  
  15. conn = DriverManager.getConnection("jdbc:mysql://" + Configuration.DATABASE_URL + ":"
  16. + Configuration.DATABASE_PORT + "/" + Configuration.DATABASE_NAME + "?" + "user="
  17. + Configuration.DATABASE_USER + "&password=" + Configuration.DATABASE_PASSWORD + "&autoReconnect=true");
  18.  
  19. }
  20. if (conn.isClosed()) {
  21.  
  22. conn = DriverManager.getConnection("jdbc:mysql://" + Configuration.DATABASE_URL + ":"
  23. + Configuration.DATABASE_PORT + "/" + Configuration.DATABASE_NAME + "?" + "user="
  24. + Configuration.DATABASE_USER + "&password=" + Configuration.DATABASE_PASSWORD + "&autoReconnect=true");
  25. }
  26.  
  27. } catch (SQLException ex) {
  28. // handle any errors
  29. System.out.println("SQLException: " + ex.getMessage());
  30. System.out.println("SQLState: " + ex.getSQLState());
  31. System.out.println("VendorError: " + ex.getErrorCode());
  32.  
  33. }
  34. return conn;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement