3 messages in com.mysql.lists.javaRe: Problems to connect
FromSent OnAttachments
Jan P. Heck27 Sep 2004 13:04 
jon gold27 Sep 2004 13:15 
Wadhwa, Amit27 Sep 2004 16:54 
Subject:Re: Problems to connect
From:jon gold (de@samizdatdigital.org)
Date:09/27/2004 01:15:22 PM
List:com.mysql.lists.java

you're positive your server is running where you think it is? ie, 'telnet localhost 3306' gets you to the mysql server? also, what happens if you try to connect to 127.0.0.1 instead of 'localhost'? sometimes i have to do this on some machines, since 'localhost' ends up resolving in a very funny (and incorrect) way.

jon

Jan P. Heck wrote:

Hy, i' am using a mysql-server on a local machine (XAMPP-project). the firewall is off the port of the mysql is 3306 i am using the following script to connect from java to mysql: import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException;

public class LoadDriver { public static void main(String[] args) { try {

Class.forName("com.mysql.jdbc.Driver").newInstance(); System.out.println("Shah"); try { Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/MyTestDatabase", "root", "rootpw" ); // Do something with the Connection .... } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } } catch (Exception ex) { System.out.println(ex); } } }

BUT I ALWAYS GET THIS MESSAGE: SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused

** BEGIN NESTED EXCEPTION **

java.net.ConnectException MESSAGE: Connection refused

STACKTRACE:

java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158) at java.net.Socket.connect(Socket.java:452) at java.net.Socket.connect(Socket.java:402) at java.net.Socket.<init>(Socket.java:309) at java.net.Socket.<init>(Socket.java:124) at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:124) at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225) at com.mysql.jdbc.Connection.createNewIO(Connection.java:1779) at com.mysql.jdbc.Connection.<init>(Connection.java:450) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411) at java.sql.DriverManager.getConnection(DriverManager.java:512) at java.sql.DriverManager.getConnection(DriverManager.java:171) at LoadDriver.main(LoadDriver.java:12)

** END NESTED EXCEPTION **

SQLState: 08S01 VendorError: 0

HELP ME PLEASE