[英]VBA connects fine but java doesn't
I am trying to connect to MYSQL
server hosted on MAMP Pro
. 我正在尝试连接到
MAMP Pro
上托管的MYSQL
服务器。 I am trying to connect from the same client machine using java and VBA
. 我正在尝试使用java和
VBA
从同一台客户端计算机进行连接。 VBA
connects fine but java gives me the error after few seconds VBA
连接正常,但几秒钟后java给我错误
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
在
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
在
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. telnet 10.0.1.1 3306
接受来自客户端计算机的连接。 My Bind address is the server IP on my.conf
我的绑定地址是
my.conf
上的服务器IP
I'm using mysql-connector-java 5.1.18
Try this for you Java DB URL: 为您尝试以下Java DB URL:
jdbc:mysql://localhost:3306/datab jdbc:mysql://本地主机:3306 / datab
You verify that this does not work. 您验证这不起作用。 Examine you class path and make sure the MySql driver is on you class path.
检查您的类路径,并确保MySql驱动程序在您的类路径上。
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. 这将在Eclipse控制台中显示错误,因此您可以在此处剪切和粘贴错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.