0

Possible Duplicate:
java.sql.SQLException: No suitable driver found for localhost test

I am trying to make my first connection to a database using Java language. Here is the code that I have so far:

import java.sql.*;

public class Database {

    public static void main(String[] args) throws Exception {

        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql:mud", "myusername", "mypassword");
        Statement stmt = con.createStatement();

    }

}

I also added MySQL connector .jar to JRE/lib/ex. I try to run the program with "java Database". I get this error:

Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:mysql:mud
at java.sql.DriverManager.getConnection(DriverManager.java:640)
at java.sql.DriverManager.getConnection(DriverManager.java:200)
at Database.main(Database.java:8)

I would appreciate any help. Thanks.

Community
  • 1
  • 1
Eleeist
  • 6,601
  • 10
  • 49
  • 76
  • 4
    possible duplicate of [java.sql.SQLException: No suitable driver found for localhost test](http://stackoverflow.com/q/8509725), [No suitable driver found for mysql](http://stackoverflow.com/q/6846914), [SQLException: No suitable driver found](http://stackoverflow.com/q/5982675) and many more (see the "Related" list on the right hand side, which is exactly the same list as you got after entering the question's title...) – BalusC Jan 18 '12 at 19:51
  • The URL you're specifying for the database is incorrect. – Jonathan Jan 18 '12 at 20:30
  • I changed to "jdbc:mysql://mud" and now it shows these errors: Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure – Eleeist Jan 18 '12 at 20:46
  • Thanks Daniel, I solved the problem. – Eleeist Jan 22 '12 at 14:23

0 Answers0