Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. private static Connection connection;
  2.  
  3. public static void main(String[] args) {
  4. connection = getConnection();
  5. }
  6.  
  7. private static Connection getConnection() {
  8. try {
  9. String url = "jdbc:mysql://localhost:3306";
  10. String username = "username";
  11. String password = "password";
  12. Connection connection = DriverManager.getConnection(url, username, password);
  13. System.out.println("Connected to MySQL");
  14. return connection;
  15. } catch (SQLException e) {
  16. e.printStackTrace();
  17. }
  18. System.err.println("Connection to MySQL failed");
  19. return null;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement