Estou tendo um problema com a linha Connection no meu código, estou tentando fazer a conexão com o banco de dados MySQL com o Netbeans porem está apresentando esse erro só na linha de conexão.
Linha: Connection cn = cc.conexion(); //incompatible types: void cannot be converted to Connection
Código:
private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
conectar cc = new conectar();
Connection cn = cc.conexion();
String nom, ape, cid, tel;
String sql;
nom = t_nom.getText();
ape = t_ape.getText();
cid = t_cid.getText();
tel = t_tel.getText();
sql = "INSERT INTO clientes (nom_cli, ape_cli, ciu_cli, tel_cli) VALUES (?, ?, ?, ?)";
try {
PreparedStatement psd = cn.prepareStatement(sql);
psd.setString(1, nom);
psd.setString(2, ape);
psd.setString(3, cid);
psd.setString(4, tel);
int n = psd.executeUpdate();
if(n > 0){
JOptionPane.showMessageDialog(null, "Registro Guardado com Sucesso !");
bloquear();
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Erro !" + ex);
}
}