Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Validation
    primarykey
    data
    text
    <p>I have a Form with a few textfields and a save button. When the buttton is pressed, it should be checked whether certain textfields are empty, and if those are empty, then an error message should be displayed, else whatever job needed should be performed. i have written the code for that, but whether the fields are empty or not, it performs the main tasks. Could someone advise please? thanks</p> <pre><code>final JButton button = new JButton("Save"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if(textField_2.equals("") || textField_3.equals("") || textField_4.equals("") || textField_5.equals("") || textField_6.equals("") || textArea.equals("") || textField_7.equals("")) { JOptionPane.showMessageDialog(frmModifyBooking, "Please fill in all fields indicated with a star (*)."); } else { try { String sql = "UPDATE vacation SET `StaffID` =?, `From` =?, `To` =?, `TotalDays` =?, `VacationType` =?, `Notes` =?, `Signature` =?, `Date` =? WHERE VacationID = ?"; PreparedStatement prest = con.prepareStatement(sql); prest.setString(1, textField_1.getText()); prest.setString(2, textField_2.getText()); prest.setString(3, textField_3.getText()); prest.setString(4, textField_4.getText()); prest.setString(5, textField_5.getText()); prest.setString(6, textArea.getText()); prest.setString(7, textField_6.getText()); prest.setString(8, textField_7.getText()); prest.setString(9, txtAUniqueStudent.getText()); prest.executeUpdate(); JOptionPane.showMessageDialog(frmModifyBooking, "Record has been updated."); } catch (SQLException e) { //System.out.println("Record couldn't be added!"); e.printStackTrace(); JOptionPane.showMessageDialog(frmModifyBooking, "Record couldn't be updated. Please try again."); } } } }); button.setBounds(280, 402, 89, 23); panel_1.add(button); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload