我正在尝试从jfxdatepicker获取日期,但是结果字符串格式与数据库中的列日期格式不匹配。这是我得到的错误 java.sql.SQLDataException:ORA-01861:文字与格式字符串不匹配
public void addEmployee(ActionEvent event) {
RadioButton chk = (RadioButton)empsex.getSelectedToggle();// Cast object to radio button
//System.out.println(empjoining.getValue());
String ch;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MMM-yyyy");
ch= dbcon.insertData("insert into employees (EMPLOYEE_ID,EMPLOYEE_NAME,FATHER_NAME,ADDRESS,AGE,CNIC,JOINING_DATE,LEAVING_DATE,EMAIL,TRANSPORT_ID,EMPLOYEE_TYPE,GENDER,PHONE_NUMBER) values (" +
"'" +empid.getText()+"','" +empname.getText()+"','" +empfname.getText()+"','" +empaddress.getText()+"'," +
"'" +empage.getText()+"','" +empcnic.getText()+"','" +empjoining.getValue().format(formatter) +"','" +empleaving.getValue()+"'," +
"'" +empmail.getText()+"','" +emptransport_id.getText()+"','" +emptype.getText()+"','" +chk.getText()+"','"+empphone.getText()+"')");
System.out.println(ch);
}
}
答案 0 :(得分:2)
您假设mpjoining.getValue()。format(formatter)可以满足您的需要,则您忘记格式化DatePicker的值,以下方法可以解决您的问题:
ch= dbcon.insertData("insert into employees (EMPLOYEE_ID,EMPLOYEE_NAME,FATHER_NAME,ADDRESS,AGE,CNIC,JOINING_DATE,LEAVING_DATE,EMAIL,TRANSPORT_ID,EMPLOYEE_TYPE,GENDER,PHONE_NUMBER) values (" +
"'" +empid.getText()+"','" +empname.getText()+"','" +empfname.getText()+"','" +empaddress.getText()+"'," +
"'" +empage.getText()+"','" +empcnic.getText()+"','" +empjoining.getValue().format(formatter) +"','" +empleaving.getValue().format(formatter)+"'," +
"'" +empmail.getText()+"','" +emptransport_id.getText()+"','" +emptype.getText()+"','" +chk.getText()+"','"+empphone.getText()+"')");