AlexJamBach
AlexJamBach

Reputation: 11

No suitable driver found for jdbc:mysql//localhost:3306/Test in Eclipse

i'm aware that this question got asked several times, but the answer is always to add the .jar to the build path. I have done this but still get the "No suitable driver found for jdbc:mysql//localhost:3306/Test" exception.

Any other ideas what could be wrong? I added some shots and my code to test the connection.

Cheers!

Already added the "mysql-connector-java-8.0.15.jar" in lib folder and build path see settings here

package jdbcdemo;

import java.sql.*;

public class Driver {

    public static void main(String[] args) {

        try {   

        Connection myConn = DriverManager.getConnection("jdbc:mysql//localhost:3306/Test","root","password");

        Statement myStmt = myConn.createStatement();

        ResultSet myRs = myStmt.executeQuery("select * from TestTable");

        while (myRs.next()) {
            System.out.println(myRs.getString("Name"));
        }
        }


        catch (Exception exc) {
            exc.printStackTrace();
    }
    }
}

Upvotes: 1

Views: 1558

Answers (1)

lquitadamo
lquitadamo

Reputation: 653

Before create a Connection you have to register driver. You can find an example here: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-usagenotes-connect-drivermanager.html

Or add this line before create connection:

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

Upvotes: 0

Related Questions