Today I appeal to you in order to ask your help for the following problem. Result that I have a table in JAVA that is connected to a BD (Mysql). I want to delete a record of this table but when I try it it marks the following error " incompatible types: String can not be converted to int ".
Then the code of the method delete
public boolean eliminarEmpleado(int cedula) {
boolean resultado = false;
try {
String sql = "Delete from tercero where id = "+cedula;
objConec.conectar();
Statement st = objConec.conex.createStatement();
int valor = st.executeUpdate(sql);
if(valor>0){
resultado = true;
}
objConec.conex.close();
st.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error al eliminar" + e.getMessage());
}
return resultado;
}
Next the code of my delete button
private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {
empleado objEmpleado = new empleado();
//Asigno el modelo para el JTable
DefaultTableModel modeloTabla = (DefaultTableModel) tblEmpleado.getModel();
//Asigno el indice del elemento seleccionado
int indice = tblEmpleado.getSelectedRow();
//Asigno al campo cedula el elemto a eliminar
//int cedula = Integer.parseInt((String)modeloTabla.getValueAt(indice,0));
int cedula = (int) modeloTabla.getValueAt(indice, 0);
//Elimino el registro de la tabla
modeloTabla.removeRow(indice);
//Elimino el registro
boolean respuesta = objEmpleado.eliminarEmpleado("delete from empleado where cedula = '"+cedula+"' ");
}
The error marks me on this line
boolean respuesta = objEmpleado.eliminarEmpleado("delete from empleado where cedula = '"+cedula+"' ");