convert String to sql.Date - seems not so easy to me

Seems easy but it appears not to be a "normal" cast.

I need a way to convert input strings into sql.date objects to store them in my DB trough PreapredStatement*.setDate().

I tried all the ways founded in forum but noone seems to works.

Anybody knows a working code sequence?

Thanks!

[314 byte] By [pentolinioa] at [2007-11-27 8:10:03]
# 1

The string needs to be in the JDBC format (yyyy-mm-dd) for the following to work:java.sql.Data theDate = java.sql.Date.valueOf(theString);

or you could do something like:java.util.Date utilDate = new SimpleDateFormat("dd.MM.yyyy").parse(theString); // or use whatever format your string is in

java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());

dwga at 2007-7-12 19:53:25 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
super perfect :Dyou've gained the rewardThanks!
pentolinioa at 2007-7-12 19:53:25 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...