• 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

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Not sure what code to pos

Post your connection string, and complete error messages.
Regards, Jan
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Dmitry Petrov
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic