1
Error in connection with bank. Can anyone help me?
package conexaoprojeto;
import java.sql.*;
import javax.swing.JOptionPane;
public class ConexaoProjeto {
private final String Driver = "com.mysql.jdbc.Driver";
private final String Url = "jdbc:mysql://localhost:3306/ConexaoProjeto";
private final String User = "root";
private final String Pass = "123456";
public Connection conn;
public Statement stmt;
public ResultSet rs;
public Statement Conectar() {
try {
System.setProperty("jdbc.drivers", Driver);
conn = DriverManager.getConnection(Url, User, Pass);
stmt = conn.createStatement();
JOptionPane.showMessageDialog(null, "Conectado com Sucesso!");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Ocorreu uma falha! Não pode ser conectado" + "\n" + ex.getMessage());
}
return stmt;
}
public void Desconectar() {
try {
conn.close();
JOptionPane.showMessageDialog(null, "Conexão fechada com sucesso!");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Conexão falhou ao ser encerrada!" + "\n" + ex.getMessage());
}
}
}
You added the mysql driver . jar in your project?
– Avelino
Related 1 Related 2
– Avelino