PreparedStatement使用之设置时间
MySQL对应时间的数据类型是dateTime,Java可以使用Timestamp进行时间赋值。PreparedStatement 选用set方法为setTimestamp
PreparedStatement stmt=null;
stmt=DbConnectionManager.getConnection().prepareStatement(sql);
1.当前时间:
Timestamp now = new Timestamp(new Date().getTime());
stmt.setTimestamp(2,now);
2字符串类型的时间
date是string类型
Timestamp timeStamp=new Timestamp(
new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”).parse(date).getTime());