Question: I am trying to connect to a JDBC MySQL database using Java, but I am getting the following error when I try to run my program:-

> 
> No suitable driver found for
>  a9442ca6-992c-411b-8bda-a42f00a0ab2e.mysql.sequelizer.com
> 
> 
> 

I downloaded the following Jar file and added it to my project:

```
    mysql-connector-java5.1.34-bin.jar

```

I'm not sure if I need to add some kind of 'import' statement in my declaration maybes? Any help would be much appreciated.

My code is as follows:-

```
package dvddblibrary;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import java.util.Scanner;

    public class DBConnect {

        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) 
        {

            try
            {
                String host = "xxx";
                String uName = "xxx";
                String uPass = "xxx";

            Connection con = DriverManager.getConnection(host, uName,   uPass);

            }
            catch (SQLException err)
            {
                System.out.println(err.getMessage());
            }
        }

    }

```

Answer: 
You need to register the driver first, which is a side effect of loading the class. Try

```
Class.forName("com.mysql.jdbc.Driver");

```

MySQL even say you need to do

```
Class.forName("com.mysql.jdbc.Driver").newInstance();

```

for some "broken Java implementations" but I never found that necessary. See <http://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-connect-drivermanager.html>.
There are two problems in your code;

1) You have to add this on the top of your try block;

```
        // Add this
        Class.forName("com.mysql.jdbc.Driver");

```

2) And **your connection string is not valid**, try a valid connection string in your host;

```
        String host = "jdbc:mysql://localhost/XXX";

```

The complete code is as below, (I have no mysql database by the way, just run this to get connection error, not "" error)

```
package dvddblibrary;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnect {

    public static void main(String[] args) {

        try {
            // Add this
            Class.forName("com.mysql.jdbc.Driver");

            //String host = "xxx";  // this is not valid, update with a valid connection string
            String host = "jdbc:mysql://localhost/XXX";
            String uName = "xxx";
            String uPass = "xxx";

            Connection con = DriverManager.getConnection(host, uName, uPass);

        } catch (SQLException err) {
            System.out.println(err.getMessage());
        } catch (ClassNotFoundException e) {
            System.out.println(e.getMessage());
        }
    }

}

```

And the output is as below, instead of getting your "**No suitable driver found**" error, I get a connection error (because I don't have a mysql database on localhost :) );

```
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.

```

If you just update the code, as far as your mysql database is up and your host is valid, **this code will work fine**.