Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. public DbConnection()
  2. {
  3. try
  4. {
  5. // This will load the MySQL driver, each DB has its own driver
  6. Class.forName("com.mysql.jdbc.Driver");
  7. // Setup the connection with the DB
  8. connection = DriverManager.getConnection("jdbc:mysql://url/team_staging?"
  9. + "user=X&password=X");
  10. }
  11. catch (ClassNotFoundException ex)
  12. {
  13. Logger.getLogger(DbConnection.class.getName()).log(Level.SEVERE, null, ex);
  14. }
  15. catch (SQLException ex)
  16. {
  17. Logger.getLogger(DbConnection.class.getName()).log(Level.SEVERE, null, ex);
  18. }
  19. }
  20.  
  21. package persistence;
  22.  
  23. public class DatabaseUtils {
  24. private DatabaseUtils() {}
  25.  
  26. public static Connection getConnection(String driver, String url, String username, String password) throws Exception {
  27. Class.forName(driver);
  28. return DriverManager.getConnection(url, username, password);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement