I want to input into my MS Access table the date that the user inputs using the Jdatechooser.
In Access I have set the Date/time column to 'short date', but any format I try won't work. Help!
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();
}
A date value carries no format. Try inserting the true date value as is:
pst.setDate(4, dateChooser.getDate());