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)我试图将日期从jdatechooser插入mysql数据库,但是它显示错误,请帮我解决这个问题,如果能为我重新输入正确的代码
答案 0 :(得分:0)
1 - 此处设置日期从jDateChooser到字符串
String dob =“”+ jDateChooser1.getDate();
2 - 要将日期插入数据库,您应首先设置格式
SimpleDateFormat Date_Format = new SimpleDateFormat(“yyyy-MM-dd”); Date_Format.format(jDateChooser1.getDate())