[Solved] JDBC always Connection Refused (but msqladmin can connect via TCP)
Posted by:
Phil S
Date: December 26, 2009 06:52AM
Hi everyone,
I've been battling this one all day and am completely stumped and exhausted.
System is Linux 2.6.30-2-amd64 on Debian squeeze/sid, MySQL 5.1.41-3-log
mysqladmin can connect fine via TCP:
mysqladmin -u root -p -h localhost --protocol tcp version
Enter password:
mysqladmin Ver 8.42 Distrib 5.1.41, for debian-linux-gnu on x86_64
...
Server version 5.1.41-3-log
Protocol version 10
Connection localhost via TCP/IP
TCP port 3306
Everything is running on localhost and there is no way I can connect using anything that uses JDBC. I've tried a number of different client apps and finally my own bit of test code.
For example:
henplus -U root -P xxxxx -J jdbc:mysql://localhost/db
gives a "Communications link failure" (but not a full trace)
I used this java fragment:
import java.util.*;
import java.sql.*;
class testmysql {
static public void main(String [] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println(" mysql connect");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "root", "xxxxx");
System.out.println(" mysql connected!");
con.close();
} catch(Exception e) {
System.out.println("exception: " + e);
System.out.println("Library path: " + System.getProperty("java.library.path"));
e.printStackTrace();
}
}
}
When run the traceback shows the root cause as being:
Caused by: java.net.ConnectException: Connection refused
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:525)
at java.net.Socket.connect(Socket.java:475)
at java.net.Socket.<init>(Socket.java:372)
at java.net.Socket.<init>(Socket.java:215)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:254)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292)
... 13 more
My experience of both JDBC and MySQL is limited, I have searched far and wide, and tried many things but to no avail, none of the many java apps I have tried can connect to the database.
Any light that anyone can shed on this would be greatly appreciated.
Best Regards,
Phil S.
Edited 1 time(s). Last edit at 12/28/2009 04:43AM by Phil S.
Subject
Written By
Posted
[Solved] JDBC always Connection Refused (but msqladmin can connect via TCP)
December 26, 2009 06:52AM
December 28, 2009 04:47AM
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.