File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Is there a MySQL server running on the machine/port you are trying to connect to? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Is there a MySQL server running on the machine/port you are trying to connect to?" Watch "Is there a MySQL server running on the machine/port you are trying to connect to?" New topic
Author

Is there a MySQL server running on the machine/port you are trying to connect to?

Dmitry Petrov
Greenhorn

Joined: Feb 27, 2010
Posts: 2
Hello!

I relatively new to Java, and am currently working on a project, for which I would like to be able to connect to an online mySQL database. One that's being hosted somewhere ... else.

For days, I have been trying to figure out why it won't work. I have tried countless tutorials on J/Connector, and they all come up with the same error;

Is there a MySQL server running on the machine/port you are trying to connect to?

In my last attempt, I have followed this tutorial, word for word.

Connecting to localhost failed, as did to GoDaddy, and FreeMySql.net, and even a public genome database.

The people over at the Java forums didn't help at all, so I come here seeking dire assistance.

Not sure what code to post, as I have tried so much, and it all comes down to the same error.

Thanks in advance!
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2476
    
    7

Not sure what code to pos
Post your connection string, and complete error messages.
Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5772
    
    7

Are you able to use the mysql command line tools to connect to the remote database?

Also, since you are just now starting out with JDBC, I would recommend that your install MySQL locally and work with that. Most tutorials assume that you will have a local MySQL database and thus use 'localhost' in the URL. Once you are comfortable with coding for your local database you can easily substitute the URL for for local database with the one for the remote database.

JBoss In Action
Dmitry Petrov
Greenhorn

Joined: Feb 27, 2010
Posts: 2
Well, here is the code;


And here is my JCreator output;

MySQL Driver Found
Connection couldn't be established to jdbc:mysql://localhost:3306/feedback
Exception in thread "main" java.sql.SQLException: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.lang.NumberFormatException)
at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at dbCon.makeCon(dbCon.java:24)
at dbCon.runMe(dbCon.java:10)
at dbCon.main(dbCon.java:63)

Process completed.

Well, I use Navicat to connect to mySQL servers, and they work fine.

As for localhost, yeah, I have tried that several times, unfortunately to no avail.
Nirmal A Janardanan
Greenhorn

Joined: Feb 28, 2010
Posts: 1
From the stack trace, it seems that the MySQL server is not running at localhost:3306
Connection couldn't be established to jdbc:mysql://localhost:3306/feedback
Exception in thread "main" java.sql.SQLException: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to?

You can do a telnet and check if MySQL is up or dead. Open your command prompt/linux console and run this cmd.
telnet localhost 3306
If it says.. "Connection refused or something similar", then MySQL service is not started. To start mysql on linux you can run
/etc/init.d/mysql start
If connection was successful, then check if you have created a database 'feedback' in mysql which you are connecting in your code.
Hope this helps


Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5772
    
    7

The problem is that you are using "localhost" in the connection URL. As you stated in your original post you are using a remote mysql server. You need to find out from that mysql provider what URL you should be using. If they don't know the URL, ask them for the host name and port number. I assume that you know the database. From that information you can build the connection URL.

The alternative is to follow my suggestion and install MySQL locally. I highly recommend that!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there a MySQL server running on the machine/port you are trying to connect to?
 
Similar Threads
MySQL is driving me nuts
Problem Connecting to MySQL Database
problem in connecting on multiple mysql database versions
Mysql+Applet Connection Problem, attention pls.
MySql Lost connection exception under load