简体   繁体   English

VBA连接正常,但Java没有

[英]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.

相关问题 奇怪的Java套接字行为(连接但不发送) - Strange Java Socket Behavior (Connects, but Doesn't Send) Java程序运行正常但不编译 - Java program runs fine but doesn't compile 在邮递员 api 中工作正常,但在 java 中却没有 - In postman api works fine but in java it doesn't Java vscode 项目无法正常工作 - Java Project for vscode doesn't works fine Java可以在“绝对”路径下正常运行,而不在指定CLASSPATH下运行 - java runs fine with 'absolute' path, doesn't run with CLASSPATH specified Hibernate连接到Postgres db,但不检索数据 - Hibernate connects to Postgres db but it doesn't retrieve data TCP。 客户端即使服务器不接受也可以连接 - TCP. client connects even if server doesn't accept him IntelliJ 调试器:连接但未注意到代码何时遇到断点 - IntelliJ debugger: Connects but doesn't notice when code runs into breakpoints Java应用程序在Eclipse上工作正常,但在部署为可运行的jar后它无法正常工作 - a Java application works fine on Eclipse but it doesn't work properly after being deployed as a runnable jar C ++代码可以正常工作,但从Java(JNI)调用时不起作用 - C++ code works fine but doesn't work when calling from Java (JNI)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM