This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Eclipse Collections Categorically: Level up your programming game and have Donald Raab on-line!
See this thread for details.
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Date type conflict...

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanx for ur help Anurag Mishra and hanx Ali Gohar..

Im taking a string date from a user in a Jsp page and Ive used the codings given below to convert string to Date

String today="27.06.2004";
SimpleDateFormat formatter= new SimpleDateFormat ("dd.MM.yyyy");
Date d = formatter.parse(today);

This gave me a java.util.Date type d.
but it didnt souit with

pstmt.setDate(2,d);
pstmt is a PreparedStatement obj.

since pstmt needs a java.sql.Date type rather than a util date.
How can I overcome this problem.

Thanx in advance for any help.
Best regs,
Jayanath
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reading the JavaDoc for java.sql.Date shows a number of ways you can do this. First, there is a java.sql.Date constructor which takes a long representation of the number of miliseconds since January 1, 1970, 00:00:00 GMT, and a getTime() method in java.util.Date which returns a long representation of the number of milliseconds since January 1, 1970, 00:00:00 GMT. Secondly, there is a setTime() method of java.sql.Date which takes a its parameter a long representation of the number of milliseconds since January 1, 1970, 00:00:00 GMT. Thirdly, there is a method of java.sql.Date called valueOf which takes a String representation of a date, and returns a java.sql.Date. Any way provides you with the functionality you need.
 
I'm sure glad that he's gone. Now I can read this tiny ad in peace!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic