Re: Can not connect to Mysql using jdbc on xp
Naomi Blythe wrote:
> It is now using Connector/J 3.1.8. Below is the
> error message that I get. The line that is
> spitting out the error is the line "cnn =
> DriverManager.getConnection("jdbc:mysql://127.0.0.
> 1:3306/prayerdiary?user=root&password=root");
>
> ****************************************
>
> com.mysql.jdbc.CommunicationsException:
> Communications link failure due to underlying
> exception:
>
> ** BEGIN NESTED EXCEPTION **
>
> java.net.SocketException
> MESSAGE: java.net.ConnectException: Connection
> refused: connect
>
> STACKTRACE:
>
> java.net.SocketException:
> java.net.ConnectException: Connection refused:
> connect
> at
> com.mysql.jdbc.StandardSocketFactory.connect(Stand
> ardSocketFactory.java:151)
> at
> com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:2
> 80)
> at
> com.mysql.jdbc.Connection.createNewIO(Connection.j
> ava:1774)
> at
> com.mysql.jdbc.Connection.<init>(Connection.
> java:437)
> at
> com.mysql.jdbc.NonRegisteringDriver.connect(NonReg
> isteringDriver.java:268)
> at java.sql.DriverManager.getConnection(Unknown
> Source)
> at java.sql.DriverManager.getConnection(Unknown
> Source)
> at PrayerDiary.<init>(PrayerDiary.java:37)
> at PrayerDiary.main(PrayerDiary.java:57)
>
>
> ** END NESTED EXCEPTION **
>
> **************************************************
Naomi,
This stack trace _really_ shows your application couldn't get a socket from
host=127.0.0.1 and port=3306. This is not caused by Connector/J.
This is caused by J2SE level.
Make sure your MySQL is already running and using the port 3306 again.
Run the following test code and check if your _any_ Java program can
access to the 127.0.0.1:3306
<pre>
public static void main(String[] args) throws Exception {
java.net.InetAddress[] addressList = java.net.InetAddress.getAllByName("127.0.0.1");
int portNumber = 3306;
java.net.Socket socket = null;
for (int i = 0; i < addressList.length; i++) {
try {
socket = new java.net.Socket(addressList, portNumber);
socket.close();
break;
} catch (java.net.SocketException e) {
// ignore
}
}
if (socket != null) {
System.out.println("OK " + socket.getInetAddress() + ":" + portNumber);
} else {
System.out.println("NG");
}
}
</pre>
--
Tetsuro IKEDA
Subject
Written By
Posted
Re: Can not connect to Mysql using jdbc on xp
June 02, 2005 02:20AM
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.