0

I am trying to set up a connection between Eclipse and MySQL. However, I am getting java.lang.ClassNotFoundException: com.mysql.jdbc.Driver exception again and again. I have already imported the mysql-connector-java into my build path and I still get the same error.

package br.com.agenda.factory;

import java.sql.Connection;
import java.sql.Driver;

public class ConnectionFactory {
    
    // Nome do usuário do mysql
    private static final String USERNAME = "root";
    
    // Senha do banco
    private static final String PASSWORD = " ";
    
    //Caminho do banco, porta, nome do banco
    private static final String DATABASE_URL = "jdbc:mysql://localhost:3307//agenda";
    
    /*
     * Conexão com o banco de dados
     */
    
    public static Connection createConnectionToMySQL() {
        Class.forName("com.mysql.jdbc.Driver");
        return null;
    }
}

In the image you can see the connector in my "referenced libraries"

troy
  • 2,145
  • 2
  • 23
  • 31

1 Answers1

0

When I see the your screenshot your source folder is red. It can not be because of the missing com.mysql.jdbc.Driver because this error you only get during runtime.

So: Most probably your project was not rebuild because of some compile errors. So fix these errors, rebuild your project and run again your code to load the DB class.

timguy
  • 2,063
  • 2
  • 21
  • 40