Results 1 to 6 of 6

Thread: Java/Eclipse - JDBC - MySQL: Communications link failure

  1. #1

    Java/Eclipse - JDBC - MySQL: Communications link failure

    maybe someone can help me with my programming problem :/

    import java.sql.*;
    public class test2 {
    	public static void main(String[] args) throws Exception {
    		Class.forName ("com.mysql.jdbc.Driver").newInstance ();
    		Connection conn = DriverManager.getConnection ("jdbc:mysql://<my_hostname>/<my_database>", "<my_username>", "<my_password>");
    And the result:

    Exception in thread "main" com.mysql.jdbc.CommunicationsException: Communications link failure
    Last packet sent to the server was 0 ms ago.
    at com.mysql.jdbc.SQLError.createCommunicationsException(
    at com.mysql.jdbc.ConnectionImpl.createNewIO(
    at com.mysql.jdbc.ConnectionImpl.<init>(
    at com.mysql.jdbc.ConnectionImpl.getInstance(
    at com.mysql.jdbc.NonRegisteringDriver.connect(
    at java.sql.DriverManager.getConnection(
    at java.sql.DriverManager.getConnection(
    at test2.main(
    Caused by:
    at java.lang.String.init(
    at java.lang.String.<init>(
    at com.mysql.jdbc.SingleByteCharsetConverter.<init>(
    at com.mysql.jdbc.SingleByteCharsetConverter.initCharset(
    at com.mysql.jdbc.SingleByteCharsetConverter.getInstance(
    at com.mysql.jdbc.ConnectionImpl.getCharsetConverter(
    at com.mysql.jdbc.StringUtils.getBytes(
    at com.mysql.jdbc.Buffer.writeStringNoNull(
    at com.mysql.jdbc.Buffer.writeString(
    at com.mysql.jdbc.MysqlIO.doHandshake(
    at com.mysql.jdbc.ConnectionImpl.createNewIO(
    ...6 more
    I'm using Ubuntu, Eclipse SDK 3.2.2 and the JDBC driver for MySQL that comes via the paketmanager (v5.1.5).

    I added /usr/share/java/mysql-connector-java-5.1.5.jar to the Build Path as an external JAR.

    The error message appears while using java-1.5.0-gcj-4.2-
    I tried java-6-sun- and openjdk as well, but with both JREs, the program just hangs up, without throwing an exception.

    It is not a problem with the database, i can connect from Windows without a problem, and using the MySQL Administrator tool, i can connect from Linux as well. So it must be a problem with JDBC (?).

    Does anyone have an idea?

  2. #2
    Join Date
    Nov 2007
    New Zealand
    Ubuntu 11.04 Natty Narwhal

    Re: Java/Eclipse - JDBC - MySQL: Communications link failure

    1. Is this a web application? If so put your db driver jar in the WEB-INF/lib/ folder

    2. In your my.cnf file (on your MySQL server) is your MySQL bound to Comment out bind-address=

    3. Do you have MySQL GUI tools installed (available in the repositories)? Try and connect to this DB using MySQL GUI tools from the same host that your program is running from.

    BTW: stick with the Sun Java 6 JDK
    Last edited by tinny; August 22nd, 2008 at 11:53 PM.

  3. #3
    Join Date
    Feb 2008
    Cape Town, South Africa
    Ubuntu 8.04 Hardy Heron

    Re: Java/Eclipse - JDBC - MySQL: Communications link failure

    Quote Originally Posted by tinny View Post
    btw: Stick with the sun java 6 jdk

  4. #4

    Re: Java/Eclipse - JDBC - MySQL: Communications link failure

    Ok thanks, i finally solved my problem. I used java-6-sun- instead of java-1.5.0-gcj-4.2- as JRE and imported the mysql-connector-java-5.1.6-bin.jar as a external JAR from and not the broken(?) 5.1.5 that comes via the paket manager.

  5. #5
    Join Date
    Aug 2008

    Re: Java/Eclipse - JDBC - MySQL: Communications link failure

    Odd, I have this problem too. I cant even connect to the db (I can from the shell and mysql administrator). The difference is I've been using the "un-broken" jar the whole time so it must have been something else you changed.

    EDIT: AHA..I was using port 3309 instead of 3306 to connect.
    Last edited by theirishfozz; October 1st, 2008 at 06:51 PM.

  6. #6
    Join Date
    Jul 2009

    Re: Java/Eclipse - JDBC - MySQL: Communications link failure

    I got the same Problem in my Java-Project.
    My fault was, that i created a SecurityManager, but didn't start the java Machine with the option -DJava Security Manager (...)

    hope that helps someone .


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts