关于向sql中插入datetime部分问题总结
作者:互联网
非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);
标签:String,format,SimpleDateFormat,插入,dateStr,sql,Date,new,datetime 来源: https://www.cnblogs.com/XiaoGao128/p/11877516.html