码迷,mamicode.com
首页 > 数据库 > 详细

java web中向postgreSQL插入当前时间

时间:2015-05-31 09:32:48      阅读:312      评论:0      收藏:0      [点我收藏+]

标签:java   web   当前时间   timestamp   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插入当前时间

标签:java   web   当前时间   timestamp   postgresql   

原文地址:http://blog.csdn.net/u012948976/article/details/46276695

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!