• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Converting String to util.Date and then sql.Date

Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am trying to convert a String to a java.util.Date and then subsequently convert it into java.sql.Date to be queried in the database. Kindly let me know if there is a better approach for this .
In Servlets I have passed a method in which i am passing 2 parameters 'String from, String to':
and then based upon I want to get all the request(having 4 columns i.e req_id, name, status, create_date) in the database between those two dates. and then subsequently put in a table .
Note: In the database the date format is eg. 8/1/01 but when i click the cell(I am using a software to access the database) a dialog window comes up and shows the date as "Wednesday, August 01, 2001" . I am not sure if there is anything to do with this ?
This is the method allRequest():

Kindly let me know how this problem could be solved.
Any help would be appreciated.

I've edited this and added spaces within the HTML tags so it doesn't mess up this page - Angela Poynton

[This message has been edited by Angela Poynton (edited August 02, 2001).]
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When dealing with dates between a DB and Java, I've found it simpler to use timestamps. For example,
Timestamp time = new Timestamp( (new java.util.Date()).getTime());
stmt.setTimestamp( 1, time );
Timestamp time = stmt.getTimestamp( "Time" );
And create some utilities form parsing you own formats
public static Timestamp getTimestamp( String day, String month, String year ) {
public static Date getTimestampAsDate( Timestamp date ) {
This seems to avoid a lot of issues since you can't argue with a date/time represented in milliseconds. Hope this helps.
Can't .... do .... plaid .... So I did this tiny ad instead:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic