0

I have Eclipse Indigo on Mac Os X and I have downloaded mysql connector (version 5.1).
I have added the jar to the project and I am using this code:

public class Test 
{
    public static void main (String[] args)
    {
        try {
        String url = "jdbc:msql://200.210.220.1:1114/Demo";
        Connection conn = DriverManager.getConnection(url,"","");
        Statement stmt = conn.createStatement();
        ResultSet rs;

        rs = stmt.executeQuery("SELECT Lname FROM Customers WHERE Snum = 2001");
        while ( rs.next() ) {
            String lastName = rs.getString("Lname");
            System.out.println(lastName);
        }
        conn.close();
    } catch (Exception e) {
        System.err.println("Got an exception! ");
        System.err.println(e.getMessage());
    }
    }
}

When I try to execute the program I get this exception:

Got an exception! 
No suitable driver found for jdbc:msql://200.210.220.1:1114/Demo

My question is : how to install the driver? What else should I do?
And once installed the driver, how do I get my database URL (I am using mysql 5.5)?
I haven't found a valid guide on the web, they're all too specific.

Ramy Al Zuhouri
  • 21,580
  • 26
  • 105
  • 187
  • http://stackoverflow.com/questions/8146793/jdbc-msql-no-suitable-driver-found-for-jdbcmysql-localhost3306-mysql – İsmet Alkan May 06 '12 at 00:47
  • This Answer is even better - http://stackoverflow.com/questions/2839321/java-connectivity-with-mysql/2840358#2840358 – Stephen C May 06 '12 at 01:06

4 Answers4

1

you're missing the "y" in jdbc:mysql

andrew cooke
  • 45,717
  • 10
  • 93
  • 143
  • correct the jdbc connection string and if you have the jdbc jar in your project classpath then it should work properly. – Sanath May 06 '12 at 07:36
1

Your JDBC connection URL is not correct, refer to the official documentation to check the required format for the URL .

In your case the URL will become :

String url = "jdbc:mysql://200.210.220.1:1114/Demo";
aleroot
  • 71,077
  • 30
  • 176
  • 213
1

You are using MySQL, the URL should look like this:

jdbc:mysql://200.210.220.1:1114/Demo

may be, review the IP and PORT.

Lena
  • 55
  • 2
  • 2
  • 9
0

You may have added the jar to your project but have you also added it to the project classpath? Having the jar exist as a file in your project won't solve the problem. The jar file is clearly not accessible to your program. Right click on your project -> Build Path -> add the jar there.

Database URL looks ok, assuming you have the right host address and port number.

Pradeep
  • 148
  • 1
  • 9