将字符串转换为java.sql.date
#学习记录:
public static void main(String[] args) {
String birthday="1997-07-21";
java.sql.Date dt=StringToDate(birthday);
System.out.println(dt);
System.out.println(dt.getClass().getName());
}
public static java.sql.Date StringToDate(String sDate) {
/**
*str转date方法
*/
String str = sDate;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date d = null;
try {
d = format.parse(str);
} catch (Exception e) {
e.printStackTrace();
}
java.sql.Date date = new java.sql.Date(d.getTime());
return date;
}