I have two jDateChooser on my dialog , I want to save to MS-SQL DB having issue with that data types. Any idea how to fix this issue ! I can only do this when i convert data type to nvarchar in DB and convert the value to string which returns from jDateChooser.
// I can save in this way but I it doesn't use jDateChooser;
java.util.Date utilDate = new java.util.Date();
java.sql.Date sqldate = new java.sql.Date(utilDate.getTime());
// I cant save the date with jDateChooser
java.sql.Date sqldate = new java.sql.Date(jDateChooser3.getDate());
// Only Way I found
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
String sd = dateFormat.format(jDateChooser3.getDate());
obj.setStartDate(sd);
//
Right click on jDateChooser. Go to the Properties and dateFormatString. Set this format: dd-MM-yyyy.
Judging from the code you posted it looks like
jDateChooser3.getDate()
returns ajava.util.Date
instance while thejava.sql.Date(millis)
constructor expects the date/time as along
milliseconds value.Use this code and it will work:
Since it comes from a date chooser component, invalid input most likely results in
null
returned date, so you might want to also check on that: