I am trying to establish a connection in my Java application with JDBC to access my online database so that I can insert and query tables. Here is what I'm trying to do now: (the actual IP / user / pass has been edited, but they are right, since I did a similar script with PHP)
String url = "jdbc:mysql://984.168.199.70/my_db_name"; String user = "my_username"; String pass = "my_password"; Class.forName ("com.mysql.jdbc.Driver").newInstance (); Connection conn = (Connection) DriverManager.getConnection(url, user, pass); stmt = (Statement) conn.createStatement();
But this does not work, I get an error message:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
And the error log is quite long after that.
So, just note: I connected to this server before using the PHP script, and I used JDBC to connect to and interact with my localhost MySQL databases.
Thanks for any help.
source share