the errors occurs when java.sql.Date imported which is derived from java.util.Date, and DateFormat.parse return a java.util.Date
. so you can't assign java.util.Date
to derived type java.sql.Date
.
import java.util.Date;
//not
import java.sql.Date;
OR assign it to a full-name type of java.util.Date
when you both using java.sql.Date
and java.util.Date
:
java.util.Date d = sdf.parse(s);
OR if you need convert java.util.Date
to a java.sql.Date
you can do as follows:
java.sql.Date d = new java.sql.Date(sdf.parse(s).getTime());
OR if you need convert java.util.Date
to a java.sql.Time
you can do as follows:
java.sql.Time d = new java.sql.Time(sdf.parse(s).getTime());