Hi. I have a form in my java inventory software that permits a shop manager to create new sales agents accounts.
It has 6 fields : firstNameField, lastNameField, dateOfBirthField, phoneNumberField, agentIDField, and agentPasswordField.
It also have a button called Add
This form stores its values in an SQLite database table called: sales_agents Here's its schema:
My goal is, when the manager clicks the Add button -- which is linked to a method called agentCreateBtnActionPerformed(), the following code should check that no field has been left blank,
before inserting anything to the database.
In case, there is an empty field, it prints out this message:
Please you are required to enter something in every empty field to carry out this operation!
Here's the code:
My Problem. 1) The above code keeps inserting empty strings when there are empty fields. And I've also realized that, when I insert something in the agentPasswordField, and don't insert anything in the
agentIDField, and vice versa, it inserts both non-empty field values and empty field values to the database without popping up an error message.
Whereas, failing to insert into the agentIDField, and agentPasswordField generates an error message in JOptionPane that says:
A primary key constraint failed (UNIQUE constraint failed: sales_agents.userID, sales_agents.userPassword)
2) I added a check constraint to the userPasswordField thinking it would generate an SQLException, but it still did not work.
I've made a lot of research on this issue online but couldn't find something that helped.