3
I am studying Java with database and I am doing some examples. On the PC with Windows I used a code and it worked, no problem occurred, now I returned to use Linux and the same code is giving error when calling the method DriveManager.getConnection
of JDBC
.
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 the following Eclipse suggests adding a cast with Connection
in:
conexao = DriverManager.getConnection(URL, USUARIO, SENHA);
I can’t understand, why make a cast
with Connection
if he’s a Connection
?
Add the error if possible to the question. If it is not a stacktrace, add an image showing the eclipse message.
– user28595