"Cannot be resolved as a type" problem with Java

69 Views Asked by At
package br.com.agenda.factory;

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

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 de dados, porta, nome do banco de dados
    
    private static final String DATABASE_URL = "jdbc:mysql://localhost:3306/agenda";

    /*
     * Conexão do banco de dados
     */
    
    public static Connection  createConnectionToMySql() {
        
        // Faz com que a classe seja carregada pela JVM
        
        Class.forName("com.mysql.jdbc.Driver")
        
        //cria a conexão com o banco de dados
        
        Connection connection = DriverManager.getConnection(DATABASE_URL, U, PASSWORD);
        
        return connection;
    }
    
    public static void main(String[] args) throws SQLException {
        // Recuperar uma conexão com o banco de dados
        Connection con = createConnectionToMySql();
        
        //Testar se a conexão é nula
        if(con!=null) {
            System.out.println("Conexão obtida com sucesso")
            con.close();
        }
            
    }
    
    
    
}

I'm trying to create a crud with Java but Eclipse it's pointing troubles with "Connection", "DriverManager" and SQLException, all of them are showing the same error message "... Cannot be resolved as a type" idk why that is happening, can somebody help me please?

Project structure

0

There are 0 best solutions below