方式一:(推荐)需要使用到java.sql.Timestamp这个类来进行转换:
Timestamp t = new Timestamp(user.getBirthay().getTime());
ps.setTimestamp(3, t);
这样就可以直接存入数据库!
方式二:我们直接将birthday转换成特定格式的字符串String,存入数据库,这样也可以!:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String birthday = df.format(user.getBirthay());
ps.setString(3, birthday);//这样和下面这样都可以!
ps.setObject(3, birthday);
Comments | NOTHING