我想将用户使用Jdatechooser输入的日期输入到MS Access表中。
在Access中,我已将“日期/时间”列设置为“短日期”,但是我尝试的任何格式均行不通。救命!
try
{
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://E:\\testing.accdb");
String sql="insert into Homework (Description,Subject_ID,Name,Due_Date) values (?,?,?,?) ";
PreparedStatement pst=conn.prepareStatement(sql);
pst.setString(1, textFieldDes.getText());
pst.setString(2, textFieldID.getText());
pst.setString(3, textFieldName.getText());
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
String date= sdf.format(dateChooser.getDate());
pst.setString(4,date);
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Data Saved");
pst.close();
}
catch (Exception e)
{
e.printStackTrace();
}
答案 0 :(得分:1)
日期值不带任何格式。尝试按原样插入真实的日期值 :
pst.setDate(4, dateChooser.getDate());