开发者

Getting a CommunicationsException in MySQL Driver when not logged in as Administrator

开发者 https://www.devze.com 2023-01-24 00:02 出处:网络
we\'re programming a software for economic calculation. We use Java 6, the Swing Application Framework, MySQL 5.1, JDBC and Hibernate (JDBC is just for an initial connection-test).

we're programming a software for economic calculation. We use Java 6, the Swing Application Framework, MySQL 5.1, JDBC and Hibernate (JDBC is just for an initial connection-test). We deployed that application on a Windows XP machine. As long as a user with administrator-privileges is running the application, it works just fine. If a user with restricted rights is trying to run it, we get an exception.

We tried to deactivate windows firewall and faced the same problem (administrator has firewall activated too!). Next we tried to reconstruct the situation at one of our computers and were not able to do so, the application runs just fine.

Our research in the internet wasn't successful, because in this case it is a very rare situation. Below is the code where the exception gets thrown and the stacktrace.

/**
  * Testet ob eine Verbindung zu der Datenbank mit den Werten aus der Properties-Datei
  * möglich ist.
  * @return true, falls die Verbindung zustande kommt
  */
public boolean testConnection(Properties props) {
    Connection conn = null;
    try {
        Class.forName(props.getProperty(SystemParameterModel.HIBERNATE_CONNECTION_DRIVER_CLASS_KEY)).newInstance();
        System.out.println("Driver: " + props.getProperty(HIBERNATE_CONNECTION_DRIVER_CLASS_KEY));
        System.out.println("URL:    " + props.getProperty(HIBERNATE_CONNECTION_URL));
        System.out.println("User:   " + props.getProperty(HIBERNATE_CONNECTION_USER_KEY));
        System.out.println("Pass:   " + props.getProperty(HIBERNATE_CONNECTION_PASSWORD_KEY));
        conn = DriverManager.getConnection(
                props.getProperty(HIBERNATE_CONNECTION_URL),
                props.getProperty(HIBERNATE_CONNECTION_USER_KEY),
                props.getProperty(HIBERNATE_CONNECTION_PASSWORD_KEY));
    } catch (SQLException ex) {
        System.out.println(ex.getLocalizedMessage());
        ex.printStackTrace();
        return false;
    } catch (Exception ex) {
        System.out.println(ex.getLocalizedMessage());
        ex.printStackTrace();
        return false;
    }
    try {
        conn.close();
    } catch (SQLException ex) {
        System.out.println("whateves..." + ex.getMessage());
    }
    return true;
}

And the Stacktrace:

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.
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
 at java.lang.reflect.Constructor.newInstance(Unknown Source)
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
 at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1118)
 at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:343)
 at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2308)
 at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
 at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
 at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
 at java.lang.reflect.Constructor.newInstance(Unknown Source)
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
 at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
 at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
 at java.sql.DriverManager.getConnection(Unknown Source)
 at java.sql.DriverManager.getConnection(Unknown Sourc开发者_C百科e)
 at com.sgp.mybe.calc.model.SystemParameterModel.testConnection(SystemParameterModel.java:153)
 at com.sgp.mybe.calc.dao.InitEntityManagerFactory.loadEMF(InitEntityManagerFactory.java:61)
 at com.sgp.mybe.calc.dao.InitEntityManagerFactory.<clinit>(InitEntityManagerFactory.java:31)
 at com.sgp.mybe.calc.dao.DaoFactory.getAttributeDao(DaoFactory.java:18)
 at com.sgp.mybe.calc.model.ValidationAttributeModel.<init>(ValidationAttributeModel.java:24)
 at com.sgp.mybe.calc.model.CalcDetailModel.<init>(CalcDetailModel.java:36)
 at com.sgp.mybe.calc.main.MybeCalcApplication.startup(MybeCalcApplication.java:46)
 at org.jdesktop.application.Application$1.run(Application.java:171)
 at java.awt.event.InvocationEvent.dispatch(Unknown Source)
 at java.awt.EventQueue.dispatchEvent(Unknown Source)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.net.SocketException: Malformed reply from SOCKS server
 at java.net.SocksSocketImpl.readSocksReply(Unknown Source)
 at java.net.SocksSocketImpl.connect(Unknown Source)
 at java.net.Socket.connect(Unknown Source)
 at java.net.Socket.connect(Unknown Source)
 at java.net.Socket.<init>(Unknown Source)
 at java.net.Socket.<init>(Unknown Source)
 at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
 at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292)
 ... 29 more

The properties are right, there's no doubt.

I hope someone can help me out, because this problem is driving me mad. Thank you!


you can refer this: https://serverfault.com/questions/89955/unable-to-connect-to-mysql-through-jdbc-connector-through-tomcat-or-externally


The problem is solved. The customer missinformed us about the proxy-settings in the local network, which produced the exception.

0

精彩评论

暂无评论...
验证码 换一张
取 消