Reputation: 281
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?
Upvotes: 2
Views: 46242
Reputation: 31841
If the date chooser
that you've mentioned is this one http://plugins.netbeans.org/plugin/658/jdatechooser-1-2 then one possible solution might be this.
String dateValue = resultset.getString(2); // Your column Name
java.util.Date date = new SimpleDateFormat("dd-MM-yyyy").parse(dateValue);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
jDateChooserDCC.setSelectedDate(cal);
Upvotes: 1
Reputation: 1
SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
Date dateValue = null;
try {
dateValue = date.parse(resultset.getstring(1));
} catch (ParseException ex) {
Logger.getLogger(pegawai.class.getName()).log(Level.SEVERE, null, ex);
}
jdateChooser.setDate(dateValue);
note : resultset.getstring(1) is data from database mysql
Upvotes: -2
Reputation: 347194
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);
Upvotes: 4