• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic