How can I set the date to the jDateChooser which is retrieved from the database?

Harshali picture Harshali · Aug 1, 2012 · Viewed 44.4k times · Source

I have a form on which I want to access a date from the database and show in jDateChooser for a particular record.

I saved the date as a string in the database.

How do I get the date from the database table and how do I set that date in jDateChooser?

Answer

MadProgrammer picture MadProgrammer · Aug 1, 2012

If you stored the date in the database as String then you're going to need to retrieve it as String

String dateValue = resultset.getString(...); // What ever column
java.util.Date date = new SimpleDateFormat("dd-MM-yyyy").parse(dateValue);

jDateChooser.setDate(date);