I am trying to connect to MYSQL
server hosted on MAMP Pro
. I am trying to connect from the same client machine using java and VBA
. VBA
connects fine but java gives me the error after few seconds
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.
On Java
String userName = "user";
String password = "pass";
String url = "jdbc:mysql://10.0.1.1/datab";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
On VBA
Sub ConnectToDatabase()
Set oConn = New ADODB.Connection
oConn.Open "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=10.0.1.1;" & _
"DATABASE=datab;" & _
"USER=user;" & _
"PASSWORD=pass;" & _
"PORT=3306;" & _
"Option=3"
End Sub
telnet 10.0.1.1 3306
accepts connection from the client machine. My Bind address is the server IP on my.conf
I'm using mysql-connector-java 5.1.18
Try this for you Java DB URL:
jdbc:mysql://localhost:3306/datab
You verify that this does not work. Examine you class path and make sure the MySql driver is on you class path.
Your code should throw an exception here:
Class.forName("com.mysql.jdbc.driver").newInstance();
To get the error, alter your code like this:
try {
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
}
catch (Exception e) {
System.out.print(e.printStackTrace());
}
This will print the error in the Eclipse console so you can cut and paste it here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.