简体   繁体   English

DatabaseException CommunicationsException:通信链接失败

[英]DatabaseException CommunicationsException: Communications link failure

I use Ubuntu & Net-beans. 我使用Ubuntu和Net-beans。 I make a java desktop database application from Netbeans wizard. 我从Netbeans向导制作了一个Java桌面数据库应用程序。 I use MySQL database which I can open & run query from its Services → Databases. 我使用MySQL数据库,可以从“服务”→“数据库”中打开并运行查询。 When I run it I got the Exception below. 当我运行它时,出现以下异常。 When I clean & Build the Project run jar file, same Exception. 当我清理并构建Project运行jar文件时,出现相同的异常。 I have installed Windows in the same machine dual boot way, and also have the same MySQL database & Java. 我已经在同一台计算机上以双启动方式安装了Windows,并且还具有相同的MySQL数据库和Java。 When I run the jar file I make using Ubuntu Netbeans, it perfectly run in Windows and show the database data. 当我运行使用Ubuntu Netbeans创建的jar文件时,它可以在Windows中完美运行并显示数据库数据。 I did the other way also, I make the same java application in Windows Netbeans using the same database and it run perfectly both withing the Netbeans and jar file. 我也做了另一种方式,我使用相同的数据库在Windows Netbeans中创建了相同的Java应用程序,并且与Netbeans和jar文件一起运行都非常完美。 But when I try to run it in Ubuntu, both in Netbeans & jar file show the below Exception. 但是,当我尝试在Ubuntu中运行它时,Netbeans和jar文件中都显示以下异常。

[TopLink Info]: 2012.01.29 11:16:58.898--ServerSession(285416048)--TopLink, version: Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007)) Jan 29, 2012 11:16:59 AM org.jdesktop.application.Application$1 run SEVERE: Application class customerrecordsu.CustomerRecordsUApp failed to launch Local Exception Stack: Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions. [TopLink信息]:2012.01.29 11:16:58.898--ServerSession(285416048)-TopLink,版本:Oracle TopLink Essentials-2.0.1(Build b09d-fcs(12/06/2007))2012年1月29日11 :16:59 AM org.jdesktop.application.Application $ 1运行严重:应用程序类customerrecordsu.CustomerRecordsUApp无法启动本地异常堆栈:异常[TOPLINK-4002](Oracle TopLink Essentials-2.0.1(Build b09d-fcs(12 / 06/2007))):oracle.toplink.essentials.exceptions。

The last packet sent successfully to the server was 0 milliseconds ago. 成功发送到服务器的最后一个数据包是在0毫秒之前。 The driver has not received any packets from the server. 驱动程序尚未收到来自服务器的任何数据包。 Error Code: 0 at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:305) 错误代码:oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:305)为0

... lot of more

Caused by: java.net.SocketException: Can't connect to SOCKS proxy:Connection refused at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:427) 引起原因:java.net.SocketException:无法连接到SOCKS代理:java.net.SocksSocketImpl.connect(SocksSocketImpl.java:427)拒绝连接

... lot of more

Below is part of 'my.cnf' file removing comments. 以下是“ my.cnf”文件中删除注释的一部分。

[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0
[mysqld]
user        = mysql
socket      = /var/run/mysqld/mysqld.sock
port        = 3306

skip-external-locking
bind-address        = 127.0.0.1

below is part of persistance.xml file 以下是persistance.xml文件的一部分

  <property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
  <property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/MyBusinessRecords"/>
  <property name="toplink.jdbc.user" value="root"/>
  <property name="toplink.jdbc.password" value="password"/>

Netbeans wizard use JPA, & Top Link. Netbeans向导使用JPA和Top Link。 I make a program without wizard by pure Java, it worked perfectly in Ubuntu as expected and show the database data. 我用纯Java编写了一个没有向导的程序,它按预期在Ubuntu上运行良好,并显示了数据库数据。 That program is below. 该程序在下面。 Both above and below use same Java MySQL connector.jar. 上方和下方均使用相同的Java MySQL Connector.jar。

public static void main(String[] args) {
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;
    int id = 0;
    String name = null;
    try {
        String url = "jdbc:mysql://localhost:3306/MyBusinessRecords";
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        con = DriverManager.getConnection(url, "root", "5843");
        if (con != null) {
            System.out.println("A database connection has been establised!");
            st = con.createStatement();
            rs = st.executeQuery("select * from COUNTRIES");
            while(rs.next()){
            id = rs.getInt(1);
            name = rs.getString(2);
                System.out.println("id = " + id + " Name = " + name);
            }
        }
    } catch (Exception e) {
        System.out.println("Problem" + e.toString());
    } finally {
        if (con != null) {
            try {
                rs.close();
                st.close();
                con.close();
            } catch (Exception e) {
                System.out.println(e.toString());
            }
            con = null;
        }
    }
}

This is my system 这是我的系统

java version "1.7.0_01" Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode) Ubuntu 11.10. Java版本“ 1.7.0_01” Java HotSpot(TM)64位服务器VM(内部版本21.1-b02,混合模式)Ubuntu 11.10。 OS type 64 bit MySQL Version- MySQL 5.1.58-1ubuntu1 MySQL Client Version 5.1.58 Socket: /var/run/mysqld/mysqld.sock 操作系统类型64位MySQL版本-MySQL 5.1.58-1ubuntu1 MySQL客户端版本5.1.58套接字:/var/run/mysqld/mysqld.sock

I read the Q & A more then 15 in this site with same question, but that now one helped me. 在同一站点上,我阅读了15遍问答,并提出了同样的问题,但现在有人帮助了我。 Please help me. 请帮我。

Try Java 1.6. 试试Java 1.6。 I had a similar issue and changed back to Java 1.6 (I had upgraded to 1_7) and the issue went away. 我遇到了类似的问题,然后又改回Java 1.6(我已升级到1_7),问题就消失了。 Probably need a different toplink or OracleDriver release for 1_7. 可能需要1_7的其他toplink或OracleDriver版本。

  String url = "jdbc:mysql://localhost:3306/MyBusinessRecords"; 

由以下原因引起:java.net.SocketException:无法连接到SOCKS代理:不存在的SOCKS代理bind-address = 127.0.0.1您可以尝试bind-address = 0.0.0.0或jdbc:mysql://127.0.0.1 :3306 / MyBusinessRecords“

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CommunicationsException:通信链接失败 - CommunicationsException: Communications link failure jdbc4.CommunicationsException:通信链接失败 - jdbc4.CommunicationsException: Communications link failure JPA-CommunicationsException:第二次连接时通信链接失败 - JPA - CommunicationsException: Communications link failure at second connection com.mysql.cj.jdbc.exceptions.CommunicationsException:通信链接失败 - com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败? - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure? Springboot java application-mysql CommunicationsException: Communications link failure - Springboot java application-mysql CommunicationsException: Communications link failure com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败 - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure MySQL:间歇性com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败 - MySQL: Intermittant com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Spring MySQL com.mysql.cj.jdbc.exceptions.CommunicationsException:通信链接失败 - Spring MySQL com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure eclipe:间歇性com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败 - eclipe: Intermittent com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM