设为首页 加入收藏

TOP

javaweb中向postgreSQL插入当前时间
2015-11-21 01:57:27 来源: 作者: 【 】 浏览:0
Tags:javaweb 中向 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);";
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇把Excel中的数据转换成Sql语句 下一篇leetcode数据库sql之DeleteDuplic..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: