• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mysql and connection refused

 
Sean Casey
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to connect to mysql through java. I have the driver downloaded and in my class path. When I use the following code:

I get this error:
java dbConnect
java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused
I get the same exception if I connect through Netbeans. So I'm wondering if this is some sort of permission problem. I can connect fine with Mysqlnavigator using the above username and password. Any ideas?? Thanks for any help.
 
Chris Brat
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I have connected to mysql before successfully and the only difference that I can find between your code and mine is in the following line:
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "knoppix", "***********");
I used the following :
con = DriverManager.getConnection
(jdbc:mysql:localhost//mydatabase");
I didnt use a password, but thats easy enough for you to set up.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the database running on the same machine you are coding on? Are you really still connecting to 'localhost' from your code?
 
Lu Battist
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may also want to be sure you don't have a personal firewall in place that is blocking port 3306. Also be sure the database is up by connecting to it from the dos prompt through mysql.
 
Sean Casey
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the responses.
The problem was that by default in the /etc/mysql/my.cnf (I'm running linux), the line for skip-networking was uncommented so it wouldn't let any network connections connect. Apparently the mysql console program, and mysqlnavigator connect through the filesystem.
Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic