Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / May 2005

Tip: Looking for answers? Try searching our database.

Can't connect to MySQL in Netbeans webapp

Thread view: 
edmccann@gmail.com - 01 May 2005 02:25 GMT
I'm using Netbeans 4.1, I've created a MySQL DB and can connect to it
fine from a standalone Java app, but I can't connect from my webapp.

I seem to always get this error when trying to get the connection:

SocketException  ConnectionException: Connection refused

Complicating matters, for some unknown reason the Tomcat output window
at the bottom of the IDE has disappeared and I can't get it back to see
my error messages.

Code:

       Class.forName("org.gjt.mm.mysql.Driver").newInstance();
       String db = "jdbc:mysql://localhost:3306/test";
       String user = "root";
       String password = "password";
       Connection c = DriverManager.getConnection(db, user, password);

I've also tried using "Class.forName("com.mysql.jdbc.Driver"); but that
didn't work either.

The JDBC driver is in the classes/lib folder of my webapp.  I guess it
finds the driver OK, just can't get the connection.

Is this a Tomcat issue?  Or general webapp issue?

Thanks...

Ed McCann
David Harper - 01 May 2005 07:26 GMT
Ed McCann wrote:
> I seem to always get this error when trying to get the connection:
>
> SocketException  ConnectionException: Connection refused
...
>         String db = "jdbc:mysql://localhost:3306/test";

Your URL seems to be well-formed.

It looks as if your client program cannot establish a TCP/IP connection
to the database server. This has nothing to do with the JDBC driver.
It's a symptom of a deeper underlying problem.

You should check the following possibilities:

1. Are you sure that your MySQL server is actually running? Can you
connect to it using the mysql command-line client, for example? Or can
you get a response using 'telnet localhost 3306'?

2. Are you sure that it is *not* running with the --skip-networking
option? You can check this using the mysql command-line client. This is
what you want to see:

mysql> show variables like 'skip_networking';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| skip_networking | OFF   |
+-----------------+-------+

3. Do you have a firewall which may be blocking connection attempts on
port 3306? This is especially likely if you are running Windows XP and
you (or your system administrator) has installed Service Pack 2, which
activates strengthened Internet security.

David Harper
Cambridge, England
Volker - 01 May 2005 08:48 GMT
"Connection refused" means there is no service listen on the destination
port.
causes can be
- the database is not listen on the port. You can verify it with
"netstat -na" on the console
- the host name is wrong. If all run on the same system and you does not
have a cluster then it should ok
- the port is wrong

Enable the JDBC logging with
DriverManager.setLogStream( System.out ) to receive more debug infos.

Volker
http://www.smallsql.de - the 100% pure Java Desktop Database with JDBC

> I'm using Netbeans 4.1, I've created a MySQL DB and can connect to it
> fine from a standalone Java app, but I can't connect from my webapp.
[quoted text clipped - 26 lines]
>
> Ed McCann
edmccann@gmail.com - 01 May 2005 18:08 GMT
1. MySQL server is running.  I can connect with the command-line
client, a standalone app, and with MySQL Query Browser.

2. The "--skip-networking" option is OFF, just as you said.

3. I turned off the firewall (ZoneAlarm) and I still couldn't connect.
The port is open in ZoneAlarm anyway.

4. I run everything on the same machine, or localhost.

5. "netstat -na" show the DB listening on 3306.

So I still don't know what's going on.  Is it some interaction with
Tomcat?
randyzapata@hotmail.com - 24 May 2005 15:17 GMT
did you ever get connected?  I am have the same problem


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.