1

I am trying to connect to a mysql database which i have hosted on a web host instead of localhost using java. i have included the mysql-connector in the java build path of the project. i have the following code:

package com;
import java.sql.*;

public class Retrieve{
    public static void main(String[] args) throws InstantiationException, IllegalAccessException
    {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String host = "mysql4.000webhost.com/a6136644_bustrac";
        String user = "";
        String password = "";
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(host, user, password);
            if(conn != null)
            {
                System.out.println("Connection Successfull");
            }
        }
        catch (SQLException e)
        {
        System.out.println(e.getMessage());
        System.exit(0);
        }
   }

}

I am not getting any error, but when i run the program, i get:

No suitable driver found for mysql4.000webhost.com/a6136644_bustrac

what can be the issue?

EDIT: the a6136644_bustrac in the host url refers to the database

3
  • Which line does it throw this error ? Commented Apr 13, 2013 at 7:37
  • am not getting any error. just the no suitable driver found message in the output when i run the program Commented Apr 13, 2013 at 7:38
  • check if the mysql-connector is included/put in all the required places . Commented Apr 13, 2013 at 7:40

1 Answer 1

1

Instead of:

String host = "mysql4.000webhost.com/a6136644_bustrac";

Try:

String host = "jdbc:mysql://mysql4.000webhost.com/a6136644_bustrac";

Explanation:

You misunderstood the concept of a JDBC url.

It must (for MySQL) at least have the basic format:

jdbc:mysql://[host:port]/[database]

Not just:

[host]

as you are using.

Check more possible formats in: http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html

Sign up to request clarification or add additional context in comments.

10 Comments

i tried that. getting this message now: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. I thought that the server is not responding, but it seems to be doing that...
That is a new error: a network error. Your app is having network-related problems to connect to the database server. Is the server really online? Can you telnet it in the 3306 port? You see, this is not the question's problem (No suitable driver for connection to mysql database web host on using java) anymore.
sorry to bother, but how do i telnet it. am new to the concept
No, no, it is no bother at all. I'm not denying help, I'm saying you'll have a better chance of solving this new specific issue in a specific question. Telnet is a program that check if a port in a server is open, don't worry about it yet: Can you tell right now if the server is really online? Who set it up?
@GauravSood - try "man telnet" or Google it. Telnet is a common command available on Windows, Linux, Mac or any other platform you are likely to encounter. You can use it as a simple diagnostic tool ... by trying to connect to the database service's host / port. The response will tell you if something is "listening"; i.e. if the database service is online at the moment.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.