I am a new guy for JAVA.
This is my mysql customer table structure.
create table Customer(
CID VARCHAR (10) primary key,
Name VARCHAR (30) not null,
LicenseID VARCHAR (10) not null,
NIC VARCHAR (10) not null,
DOB date not null,
Address VARCHAR (25) not null,
Tp int (10) ,
Email VARCHAR (30) not null
);
This is my customerController function.
private CustomerController custController;
private void addCustomerBtnActionPerformed(java.awt.event.ActionEvent evt) {
CustomerDTO customer = new CustomerDTO(
idTxt.getText(),
nameText.getText(),
licenseText.getText(),
NICText.getText(),
DOBText.getText(),
addressText.getText(),
Integer.parseInt(tpText.getText()),
emailText.getText());
try {
boolean result = custController.add(customer);
if (result){
JOptionPane.showMessageDialog(this, "Customer has been successfully added...");
}else{
JOptionPane.showMessageDialog(this, "Customer has not been added...");
}
} catch (Exception ex) {
Logger.getLogger(addCustomer.class.getName()).log(Level.SEVERE, null, ex);
}
}
This is my add customer controller.
@Override
public boolean add(CustomerDTO dto) throws Exception {
String SQL="Insert into Customer values(?,?,?,?,?,?,?,?)";
PreparedStatement stm=connection.prepareStatement(SQL);
stm.setObject(1,dto.getCID());
stm.setObject(2,dto.getName());
stm.setObject(3,dto.getLicenseID());
stm.setObject(4,dto.getNic());
stm.setObject(5,dto.getDob());
stm.setObject(6,dto.getAddress());
stm.setObject(7,dto.getMobile());
stm.setObject(8,dto.getEmail());
int res=stm.executeUpdate();
return (res > 0);
}
When I add the new customer, it is added to database and also it show this message : "Customer has been successfully added...". But when i try to add an existing CID or Tp as a string, I can't see the "Customer has not been added..." message. Please can anyone help me solve this problem?