0
ps.setString(26, ((JTextField) Birthday.getDateEditor().getUiComponent()).getText());

That is my code how can i Convert the date format into MMM d, yyyy because the default format of my JDateChooser is yyyy-MM-dd.

Xyryle Buen
  • 43
  • 2
  • 12
  • 1
    `SimpleDateFormat`, but why not store the `Date` as a `Date` in the database? – MadProgrammer Apr 15 '15 at 06:13
  • Get the `Date` value from the `JDateChooser#getDate`, use this to store the value in the database, you may need to create a `java.sql.Date` value from it though – MadProgrammer Apr 15 '15 at 06:44

1 Answers1

0

Try this:

DateFormat f = new SimpleDateFormat("MMM d, yyyy");
ps.setString(26, f.format(((JTextField) Birthday.getDateEditor().getUiComponent()).getText()));

CORRECTION

DateFormat f = new SimpleDateFormat("MMM d, yyyy");
ps.setString(26, f.format(Birthday.getDate()));
Blip
  • 3,061
  • 5
  • 22
  • 50
  • `Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Date` - You can't `format` a `String` value – MadProgrammer Apr 15 '15 at 06:35
  • @MadProgrammer I am sorry I did not see the whole code. what is the type of `Birthday` object. – Blip Apr 15 '15 at 06:42
  • I still want to know why the OP isn't storing the date value as a date – MadProgrammer Apr 15 '15 at 06:51
  • by the way what is the type of the `ps` object? – Blip Apr 15 '15 at 06:53
  • Like a `PreparedStatement` – MadProgrammer Apr 15 '15 at 06:55
  • do you want to use `ps.setDate()` method? – Blip Apr 15 '15 at 06:57
  • I don't, but I think the OP should, as this would make it simpler to store the value without needing to mess with the date format – MadProgrammer Apr 15 '15 at 06:58
  • Could you explain a bit more about you comment about " make it simpler to store the value ". like what you want actually? – Blip Apr 15 '15 at 07:00
  • First, remember, I'm not the person who posted the question. The OP should be storing date information as a date type, allowing for time zones and the such, rather the storing it as a `String` where everybody who wants to read the data will need to know the format it's stored and the time zone it originated from just so they can read it properly. – MadProgrammer Apr 15 '15 at 07:03
  • @madprogrammer firstly I am sorry for mistaking you as the person asking the question. After you pointed out I noticed it. What you have pointed out is perfectly correct and it would always be advisable to use `setDate` method of the `PreparedStatement` in the database column should be of type `DATE` to accomodate for the same and store the correct data. – Blip Apr 15 '15 at 07:10
  • Sorry for the late reply. i just want to change the format of the date. – Xyryle Buen Apr 15 '15 at 09:07
  • i try the code that you answer but it's not saving in the database – Xyryle Buen Apr 15 '15 at 09:08
  • oh sorry its working now.. i tried the Correction code.. THANK YOU! – Xyryle Buen Apr 15 '15 at 09:13
  • I can't vote up on your answer because im new in this website – Xyryle Buen Apr 15 '15 at 09:14