I appeal to you since I have a question and can not think of anything to solve it. I comment I'm doing a CRUD in Java with the BD Mysql. I have done almost all the buttons, I just need to update. It turns out that I want the Save button to also update the fields. That is, when I select a field in the table, I load it in the JFields and then modify them and save them with the same button without creating a new one.
I have the following example.
private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {
terceros objTercero = new terceros();
String nombres = txtNombres.getText();
String apellidos = txtApellidos.getText();
int telefono = Integer.parseInt(txtTelefono.getText());
int id = Integer.parseInt(txtId.getText());
if(id == 0){
boolean resultado = objTercero.insertartercero(nombres,apellidos,telefono);
if(resultado == true){
JOptionPane.showMessageDialog(null, "Se inserto un nuevo registro");
cargarTabla();
}else{
JOptionPane.showMessageDialog(null, "Error al insertar");
}
}else{
boolean resultado = objTercero.actualizartercero(id, nombres,apellidos,telefono);
if(resultado == true){
JOptionPane.showMessageDialog(null, "Se inserto un nuevo registro");
cargarTabla();
}else{
JOptionPane.showMessageDialog(null, "Error al insertar");
}
}
As you can see there is a condition in which the id = 0, in that table the ID is not supplied since it is autoincrementable. But in the table that I'm doing the ID is the identification of the user so I can not leave it at 0. I would like to please help me think of a condition similar to the previous one.
Thank you very much!
Thanks for your reply.
I've been thinking about something and it seems a bit like what you say. The idea that I have is that, before inserting the data, to put a sentence that evaluates to me if the id exists in the BD, if it is so that I update the record, otherwise I keep the record. But the problem is that when I do the query is to say. Axis: String query="Select fron ..."; After that I want a variable of Boolean type to store the result. If the query was executed then send me a Boolean value and then program that value into a conditional. If it is true (that is, the data is in the DB) I update it and if not, it saves the value. I could not do the Boolean type. Could you help me please ?