gpt4 book ai didi

java - Datepicker日期格式与oracle数据库日期不匹配

转载 作者:行者123 更新时间:2023-12-02 01:45:45 26 4
gpt4 key购买 nike

我试图从 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);
}
}

最佳答案

您忘记格式化 empleaving DatePicker 的值,假设 mpjoining.getValue().format(formatter) 正在执行您需要的操作,以下内容应该可以解决您的问题:

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()+"')");

关于java - Datepicker日期格式与oracle数据库日期不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53693394/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com