kostas trichas
kostas trichas

Reputation: 3013

Cannot find JDBC driver

try
        {
            String userName = "root";
            String password = "";
            //<facility> is my database
            String url = "jdbc:mysql://localhost/facility";
            Class.forName ("com.mysql.jdbc.Driver").newInstance ();
            conn = DriverManager.getConnection (url, userName, password);
            System.out.println ("Database connection established");
        }
        catch (Exception e)
        {
            System.out.println ("Cannot connect to database server " +e.getClass().getName());

        }

output> Cannot connect to database server java.lang.ClassNotFoundException

Upvotes: 0

Views: 17137

Answers (3)

Johann du Toit
Johann du Toit

Reputation: 2667

To use the MYSQL Driver (Connector/J) you will need to download it from MySQL Connectors and put it in your classpath.

Upvotes: 2

Lokesh Sah
Lokesh Sah

Reputation: 2293

Download the jdbc-mysql driver here.

Include it in your classpath.

Upvotes: 1

卢声远 Shengyuan Lu
卢声远 Shengyuan Lu

Reputation: 32004

It seems that you should put your MySQL driver jar into your classpath.

Upvotes: 3

Related Questions