I'm doing a program that looks for a license plate in the database, and if it does not find it executes a sentence, and if there already exists the license plate that executes another one, but always (exists or not) executes the one that says not to be null I have tried the following code in the ActionPerformed
of the button:
try {
if(cn.BuscarMatricula(txt_Matricula.getText()).wasNull()){
JOptionPane.showMessageDialog(this, jComboBox2.getSelectedItem());
//cn.InsertarDatos(jComboBox2.getSelectedItem().toString(), txt_Modelo.getText(), txt_Matricula.getText(), txt_NIF.getText(),reparacion);
}else{
cn.actualizarMatricula(reparacion, Integer.parseInt(txt_ID.getText()));
JOptionPane.showMessageDialog(this, "Actualizado correctamente");
}
} catch (SQLException ex) {
Logger.getLogger(GestionVehiculos.class.getName()).log(Level.SEVERE, null, ex);
}
And here I attach the method of actualizarMatricula
:
public void actualizarMatricula(boolean enReparacion, int id){
Connection cn = Conectar();
Statement st;
ResultSet rs = null;
try{
PreparedStatement pst = cn.prepareStatement("UPDATE vehiculos SET reparacion = ? WHERE id = ?");
pst.setBoolean(1, enReparacion);
pst.setInt(2, id);
pst.executeUpdate();
}catch(Exception e){
Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, e);
}
}
searchCard:
public ResultSet BuscarMatricula(String matricula){
Connection cn = Conectar();
Statement st;
ResultSet rs = null;
try{
PreparedStatement pst = cn.prepareStatement("SELECT * FROM vehiculos WHERE matricula = ?");
pst.setString(1, matricula);
rs = pst.executeQuery();
}catch(Exception e){
Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, e);
}
return rs;
}
Any reason why it always enters the else, exists or not? I do not get the error, and the log shows that whatever I do tries to parse the ID that is in the else.