Guest User

Untitled

a guest
Jul 27th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. Connection between Java and MYSQL server
  2. package enceladus.db;
  3.  
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.SQLException;
  7.  
  8. public class JDBCTest{
  9. private Connection conn = null;
  10. public void connect(){
  11. try {
  12. Class.forName("com.mysql.jdbc.Driver").newInstance();
  13. System.out.println("test");
  14. conn = DriverManager.getConnection("jdbc:mysql://mysql.agh.edu.pl:3306/sadecki","sadecki","top_secret_password");
  15. System.out.println("test2");
  16.  
  17.  
  18. } catch (SQLException ex) {
  19. // handle any errors
  20. System.out.println("SQLException: " ex.getMessage());
  21. System.out.println("SQLState: " ex.getSQLState());
  22. System.out.println("VendorError: " ex.getErrorCode());
  23. }catch(Exception e){e.printStackTrace();}
  24. }
  25.  
  26. test
  27. SQLException: Communications link failure
  28.  
  29. The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
  30. SQLState: 08S01
  31. VendorError: 0
  32.  
  33. conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/sadecki","sadecki","top_secret_password");
Add Comment
Please, Sign In to add comment