private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
String G_ID=gIDText.getText();
String G_Title=(String) titleCombo.getSelectedItem();
String FName=fNameText.getText();
String SName=sureNameText.getText();
String Sex=(String) genderCombo.getSelectedItem();
String dob=(JTextField)dobDte.getDateEditor().getUiComponent().getText();//error
int age=Integer.parseInt(ageText.getText());
String country=contactText.getText();
String nationality=nationText.getText();
String ZipCode=zipCodeText.getText();
String email=mailText.getText();
String PassportNo=passportText.getText();
String IssuedDate=(JTextField)issDte.getDateEditor().getUiComponent().getText();//Error
String ExpiryDate=(JTextField).getDateEditor().getUiComponent().getText();//error
String PIDNo=pidText.getText();
int ContactNo=Integer.parseInt(contactText.getText());
Guest guest=new Guest(G_ID,G_Title,FName,SName,Sex,dob,age,country,nationality,ZipCode,email,PassportNo,IssuedDate,ExpiryDate,PIDNo,ContactNo);
try {
boolean isAdded=GuestController.addGuest(guest);
if (isAdded) {
JOptionPane.showMessageDialog(NewGuest.this,"Registered Success !");
}else{
JOptionPane.showMessageDialog(NewGuest.this,"Unable to Register ! !");
}
}catch(SQLException | ClassNotFoundException ex){
JOptionPane.showMessageDialog(NewGuest.this,ex.getMessage());
}
}
(mvc)I have tried to insert date from jdatechooser to mysql database,but its shows error,please help me to fix this and if can please retype the correct code for me
1 - here to set the date from jDateChooser to string
String dob=""+jDateChooser1.getDate();
2 - to insert the date to database you should set the format first
SimpleDateFormat Date_Format = new SimpleDateFormat("yyyy-MM-dd"); Date_Format.format(jDateChooser1.getDate())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.