Unable To Connect MYSQL Database from eclipse.

The OpenShift forums have been retired.
You can still read and search them, but for help, please post a question on Stack Overflow.

Error Message:

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:411)

at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121)

at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:355)

at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2479)

at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516)

at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301)

at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)

at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)

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:411)

at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)

at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.createConnection(JDBCConnection.java:214)

at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:105)

at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:54)

at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.open(JDBCConnection.java:73)

at org.eclipse.datatools.enablement.internal.mysql.connection.JDBCMySQLConnectionFactory.createConnection(JDBCMySQLConnectionFactory.java:28)

at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)

at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:359)

at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)

at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)

at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

Caused by: java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(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:259)

at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:305)

... 22 more

Are you using the Eclipse plugin as detailed here?: https://www.openshift.com/blogs/getting-started-with-eclipse-paas-integration

If so, you should be able to run port-forwarding from Eclipse to connect to the remote mysql DB running on the OpenShift gear (see step 10).

Yes using eclipse plugin, even though port forwarding is running (right click on the server then go to open shift-->port forwarding), it is still not able to connect to MySQL from eclipse, same connection refused error is coming.

After setting up port-forwarding, try using tools like mysql workbench or mysql command line tools to see if connections are successful to mysql server on OpenShift.

Also do share your jdbc url so we can check if it is right format.

This is the url, I am using to connect from eclipse data source explorer. jdbc:mysql://127.7.206.129:3306/testapp?autoReconnect=true I don't have mysql workbench in my machine now. I wanted to do it from eclipse only. I can connect to mysql through phpAdmin from browser with same credentials.

Check instructions outlined here and see if you are doing anything differently?

https://community.jboss.org/en/tools/blog/2012/02/08/debugging-and-browsing-openshift-applications-in-eclipse

This post has incorrectly mentioned to use openshift's IP in connection url where it must be localhost's IP (127.0.0.1)

Thanks for point it out, although both should work ..

devaskht,

Unless you're running on Linux, the port-forwarding should let you connect on a socket opened on 127.0.0.1:3306 and which will forward packets to 127.7.206.129 which is probably the IP address for the gear running your MySQL instance on OpenShift.

Can you try with 127.0.0.1:3306 instead ?

Best regards, Xavier

Thanks Coulon, it is working now. I incorrectly used openshift's ip in my coonection url instead of 127.0.0.1. :-) It is working with localhost's IP, but not with openshift's IP where my sql is running.

By the way, how to run the openshift application locally before deploying it on the cloud. It seems the publish process is taking sometime and it is tedious to publish every time we make a change to code.

Hello,

You should actually develp and test on a local app server, and then once you're happy with your code, you can publish on OpenShift. The roundtrip will be much faster on your local machine. On OpenShift, you'll have at minimum a maven build (if you have a Java project), and the app server may be stopped/restarted (unless you put the hot_redeploy marker file in the .openshift/markers directory).

Best regards, Xavier