本文主要是介绍java web中向PostgreSQL插入当前时间,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
方式1 常用插入方式
Timestamp currentTime= new Timestamp(System.currentTimeMillis());
String sql = "INSERT INTO message(date_create) VALUES (" + "'" + currentTime + "'" + ");";
方式2 使用 占位符
Timestamp currentTime= new Timestamp(System.currentTimeMillis());
String sql = "INSERT INTO message( date_create) VALUES (?);";
PreparedStatement pst = conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
pst.setTimestamp(1, currentTime);
pst.executeUpdate();
pst.close();
方式3 使用postgreSQL自带函数
String sql = "INSERT INTO message(date_create) VALUES (LOCALTIMESTAMP);";
这篇关于java web中向PostgreSQL插入当前时间的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!