非int型数据要加单引号,
用format格式化当前时间后用String插入即可
读取时用时间戳读取datetime或转化为string存储
读
public static String gainTime(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = sdf.format(date);
System.out.println(dateStr);
return dateStr;
}
user.setTime(gainTime(rsst.getTimestamp("creat_time")));
存
SimpleDateFormat timeFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss");
Date time=new Date();
String sqldate=timeFormat.format(time);
String s = "insert into master values(" + "\'" + username + "\',\'" + password + "\',\'"+sqldate +"\')";
sql.executeUpdate(s);