I'm new when it comes to java and a doubt arose and I can not find anywhere to solve it. I'm doing a project to learn well how to use Netbeans and mysql. My question is the following: I am using a catch to show messages according to the error. My problem is that I want to use the same catch but show me 2 different messages, how can I do that?
}catch(com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException e) {
JOptionPane.showMessageDialog(null, "El código postal no existe o no esta cargado","ADVERTENCIA",JOptionPane.WARNING_MESSAGE);
Ayudaloc abrir = new Ayudaloc();
abrir.setVisible(true);
}catch(com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException e) {
JOptionPane.showMessageDialog(null, "La provincia no existe o no esta cargada","ADVERTENCIA",JOptionPane.WARNING_MESSAGE);
Ayudaprov abrir = new Ayudaprov();
abrir.setVisible(true);
I hope you can help me Since the province or locality is incorrect, it always shows me the locality help table and never the provincial one.
This is the button that I use to save the data
private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {
if (txtclnombre.getText().equals("") || txtclapellido.getText().equals("") || txtcldireccion.getText().equals("") || txtclcodigopostal.getText().equals("") || txtcltelefono.getText().equals("") || txtclemail.getText().equals("")){
JOptionPane.showMessageDialog(null, "Complete todos los campos, faltan datos","ADVERTENCIA",JOptionPane.INFORMATION_MESSAGE);
} else {
try {
PreparedStatement pps = cn.prepareStatement("INSERT INTO clientes(cl_Nombre,cl_Apellido,cl_direccion,cl_cp,cl_telefono,cl_email,cl_provincia)VALUES(?,?,?,?,?,?,?)");
pps.setString(1, txtclnombre.getText());
pps.setString(2, txtclapellido.getText());
//pps.setString(3, txtcldni.getText());
pps.setString(3, txtcldireccion.getText());
pps.setString(4, txtclcodigopostal.getText());
pps.setString(5, txtcltelefono.getText());
pps.setString(6, txtclemail.getText());
pps.setString(7, txtclprovincia.getText());
pps.executeUpdate(); //ejecutar actualizacion/cambio
JOptionPane.showMessageDialog(null, "Datos Guardados");
limpiar(); //limpia los campos
mostrartabla("");
}catch(com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException e) {
JOptionPane.showMessageDialog(null, "El código postal no existe o no esta cargado","ADVERTENCIA",JOptionPane.WARNING_MESSAGE);
Ayudaloc abrir = new Ayudaloc();
abrir.setVisible(true);
}catch(com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException e) {
JOptionPane.showMessageDialog(null, "La provincia no existe o no esta cargada","ADVERTENCIA",JOptionPane.WARNING_MESSAGE);
Ayudaprov abrir = new Ayudaprov();
abrir.setVisible(true);
} catch (SQLException ex) {
Logger.getLogger(PantallaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
}
}
}