Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date Formatting issue --- Plz help...

 
Abhishek Dwaraki
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,
I'm using the SimpleDateFormat class to format my date and time in my program. The issue is that with the formatting of the system date, the am/pm marker is being returned in upper case. I need to store this in the database which could lead to issues later... Hence I need to format it in such a way that I obtain it in lowercase and I can't use the normal method of toLower() or anything like that.. I did not find any pattern string in the class that could return the marker in lowercase... Can someone help me out with this plzzzzzzzz....? Thanks in advance...
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should not store the date as a string in the DB,
use setDate() method in PreparedStatement. then the JDBC driver will take care of this.

pascal
 
Abhishek Dwaraki
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The date is being stored as a Date object itself in the DB... And also the thing is i checked the documentation for the setDate() and setTime() methods in the PreparedStatement interface. I just specifies the MM.dd.yyyy format or the hh:mm:ss format. There is no mention of the AM/PM marker in the formatting. Plz do advice further in this regard. Thanks in advance.
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where do you specify the date format pattern in PreparedStatement ??
 
Abhishek Dwaraki
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not leaving the formatting to setDate() or rather don't want to take it till there. Want to just finish with the formatting in the Java code without going till the JDBC driver. All the same, I did check out the setDate() method only after you gave me the idea. The only parameters that it took was the index position and the date. The date object while being created took only one parameter to the constructor, that was the time or date, depending on the class being used. There is no place where to specify the format string. Or maybe I was not good enough to find it. Please advice in this regard Pascal ... Thanks a lot.
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the formatting is done by the JDBC driver in the correct way (PreparedStatement is a interface which will be implemented by MySQL, Oracle, MSSql driver and so on).
so all you have to use is setDate() and do not care about the formatting.

you should not need to deal with formatting date for JDBC.

pascal
 
Abhishek Dwaraki
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the help pascal... It was a great help... Thanks once again...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic