0

I'm learning MySQL and I get this problem:

No suitable driver found for jdbc:mysql//localhost:3306/demo?useSSL=false I have read other solutions but it's not working. This is my code:

package jdbc.test;
import java.sql.*;

public class JdbcInsertDemo {
    public static void main(String[] args) throws SQLException {

        Connection myConn = null;
        Statement myStmt = null;
        ResultSet myRs = null;

        String dbUrl = "jdbc:mysql//localhost:3306/demo?useSSL=false";
                //      jdbc:mysql//localhost:3306/demo?useSSL=false    
        String user = "student";
        String pass = "student";

        try {
            myConn = DriverManager.getConnection("jdbc:mysql//localhost:3306/demo?useSSL=false", user, pass);
            myStmt = myConn.createStatement();
            System.out.println("Inserting a new employee to database\n");

            int rowsAffected = myStmt.executeUpdate("Insert into employees" + "(last_name, first_name, email, department, salary)" + "values" + "('Wright' , 'Eric', 'eric.wright@foo.com', 'HR', 33000.00)");
            myRs = myStmt.executeQuery("slect * from employees order by last_name");

            while(myRs.next()) {
                System.out.println(myRs.getString("last_name") + ", " + myRs.getString("first_name"));
            }
        }

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

        finally {
            if (myRs != null) {
                myRs.close();
            }
        }
    }
}
GJL
  • 143
  • 8
  • Duplicate? https://stackoverflow.com/questions/49490969/no-suitable-driver-found-for-jdbcmysql-localhost3306-demousessl-false – cruxi Mar 26 '18 at 12:32
  • Possible duplicate of [No suitable driver found for 'jdbc:mysql://localhost:3306/mysql](https://stackoverflow.com/questions/8146793/no-suitable-driver-found-for-jdbcmysql-localhost3306-mysql) – cruxi Mar 26 '18 at 12:33

3 Answers3

0

I think you forgot to include jar file in lib folder. Put the drive jar file in that folder and try again.

0

Theres a few things that could be wrong.

1 : Do you have the JDBC Jar included in the project references?

    myConn = DriverManager.getConnection("jdbc:mysql//localhost:3306/demo?useSSL=false", user, pass);

Also, for shorthand, since you have 'DbUrl' - MyConn can be simplified.

    String dbUrl = "jdbc:mysql//localhost:3306/demo?useSSL=false";
    myConn = DriverManager.getConnection(dbUrl, user, pass);
EightSquared
  • 37
  • 2
  • 13
0

You have missed the Class.forName("com.mysql.jdbc.Driver"); This line needs to be added before you get the connection object.

Jerin D Joy
  • 750
  • 6
  • 11