MySQL Forums :: Connector/JDBC and Java :: Communications link failure


Advanced Search

Communications link failure
Posted by: david bennett ()
Date: January 16, 2008 01:14AM

Hey,

This is my first time using the jdbc:mysql driver but ive used both Java and mySQL for years.

The mysql server works fine from a CLI or PHP.

Im having an issue connecting to mysql via this driver via both a Java class i made and SQuirreL SQL.

The message i get back from both is:
-----------------------------------------------
-----------------------------------------------

Communications link failure

Last packet sent to the server was 0 ms ago.

-----------------------------------------------
-----------------------------------------------

The full Exception/Stacktrace from java is:
-----------------------------------------------
---------- START JAVA EXCEPTION -------
-----------------------------------------------

SQLException: Communications link failure

Last packet sent to the server was 0 ms ago.
SQLState: 08S01
VendorError: 0

***** START STACK ******

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2104)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at org.red5.server.webapp.TodayTonight.mysql.Connect(mysql.java:23)
at org.red5.server.webapp.TodayTonight.mysql.main(mysql.java:85)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:209)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2027)

... 13 more

***** END STACK ******

-----------------------------------------------
----------- END JAVA EXCEPTION --------
-----------------------------------------------

My java src is:

-----------------------------------------------
-------------- START JAVA SRC -----------
-----------------------------------------------
package org.red5.server.webapp.TodayTonight;

import java.sql.*;

class mysql {

public static Connection conn = null;
public static void Connect(String User, String Pass, String Host, String DB)
{
try
{
//Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Class.forName ("com.mysql.jdbc.Driver");
}
catch(Exception e)
{
System.out.println("Error: " + e);
}
//String url = "jdbc:mysql://"+Host+":3306/"+DB+"?user="+User+"&password="+Pass;
String url = "jdbc:mysql://localhost:3006/"+DB;
try
{
conn = DriverManager.getConnection (url, User, Pass);
//conn = DriverManager.getConnection (url);
System.out.println ("Database connection established");
}
catch (SQLException ex)
{
System.out.println("Connection was not established");
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
System.out.println("\n\n***** START STACK ******\n");
ex.printStackTrace();
System.out.println("\n***** END STACK ******");
}
}
public static void Disconnect()
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) {}
}
}

public static void main (String[] args)
{
Connect("root","<password>","localhost","mysql");
}
}
-----------------------------------------------
--------------- END JAVA SRC ------------
-----------------------------------------------

Any light on this issue would be great

PS: my testing server is on the same PC running XP Pro SP2 and using MYSQL 5.0 and JAVA jdk 1.6

Options: ReplyQuote


Subject Written By Posted
Communications link failure david bennett 01/16/2008 01:14AM
Re: Communications link failure Ba Pham 01/17/2008 10:10AM
Re: Communications link failure david bennett 01/28/2008 11:35PM
Re: Communications link failure zattarz za 02/02/2008 08:03AM
Re: Communications link failure clovis harada 02/25/2008 05:54PM
Re: Communications link failure Christophe Schermesser 03/10/2008 02:55PM
Re: Communications link failure Alan Williamson 03/11/2008 12:09AM
Re: Communications link failure sol zew 01/19/2009 11:24PM
Re: Communications link failure joe bravo 04/22/2008 01:00AM
Re: Communications link failure Gerson Porras 03/02/2009 04:22PM
Re: Communications link failure marcelo farias 03/13/2009 02:37PM
Re: Communications link failure Gert Cuppens 04/12/2009 04:04AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.