MySQL Forums
Forum List  »  Connector/JDBC and Java

[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 {
System.out.println(" mysql connect");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "root", "xxxxx");
System.out.println(" mysql connected!");
} catch(Exception e) {
System.out.println("exception: " + e);
System.out.println("Library path: " + System.getProperty("java.library.path"));

When run the traceback shows the root cause as being:

Caused by: Connection refused
at Method)
at com.mysql.jdbc.StandardSocketFactory.connect(
at com.mysql.jdbc.MysqlIO.<init>(
... 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.

Options: ReplyQuote

Written By
[Solved] JDBC always Connection Refused (but msqladmin can connect via TCP)
December 26, 2009 06:52AM

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.