I'm studying Java with database and I'm doing a few examples. On the PC with Windows I used a code and it worked, there was no problem, I now use Linux and the same code is giving error when calling the% with% of DriveManager.getConnection
.
Follow the code below.
package br.com.utd.jdbc;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import com.mysql.jdbc.Connection;
public class Conexao {
private final static String URL = "jdbc:mysql://127.0.0.1:3306/livraria";
private final static String USUARIO = "root";
private final static String SENHA = "**********";
public static Connection factoryConexao(){
Connection conexao = null;
try{
conexao = DriverManager.getConnection(URL, USUARIO, SENHA);
return conexao;
}catch(SQLException e1){
JOptionPane.showMessageDialog(null,
"Falha na conexão com o banco de dados:"+e1);
return conexao;
}
}
}
The error is as follows Eclipse suggests adding a cast with JDBC
to:
conexao = DriverManager.getConnection(URL, USUARIO, SENHA);
I can not understand why to make a Connection
with cast
if it's a Connection
?