• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

connection problem with mysql

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i'm using j2sdk1.4.2 & mysql 3.x and i'm having a problem with connecting these two. i'm using the latest connector, which mysql-connector-java-3.0.14-production-bin.jar, and i followed all the steps for installing this driver. i've already set the classpath to where the connector is. but i'm still having some problems.
this error occurs :
unable to connect to any hosts due to exception : java.net.ConnectException: Connectionrefused: connect

what should i do?
here's the code i've been using to check the connection

import java.sql.*;

public class JdbcExample1 {

public static void main(String args[]) {

try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql:///mysql");

if(!con.isClosed())
System.out.println("Successfully connected to MySQL server...");

} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
e.printStackTrace();
}
} }
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you overdid the slashes in your URL, but that's a different problem.

First, check to make sure that the MySQL server is running (just in case!)

Secondly, check to see if it's listening on the tcp/ip port that your JDBC driver is expecting to talk on (it may be 1033 for MySQL, but I'd check, 'cause I don't rightly remember). netstat is your friend.

Third, make sure MySQL wishes to talk to you. I think you can get a "connection refused" if it checks your host address and finds that that host isn't authorised to talk to the database you wish to use.

*** WARNING *** The messages that MySQL return in the above case LIE. MySQL does a reverse lookup on the incoming IP address and uses THAT hostname to validate, despite reporting the failure being against YOUR hostname.

r maybe it's vice versa. Every time I set up a MySQL server I get into fights with it over that. MySQL does provide a utility program to lookup hostnames, BTW. It can be used to help you.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... and don't you need a username/ password to connect?

DriverManager.getConnection("jdbc:mysql:/mysql", "admin", "supersecret");
 
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic