• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date type conflict...  RSS feed

 
Jayanath
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!