如何使用jdbc从java类在TIMESTAMP列(Oracle)中插入当前时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16319419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to insert Current time in TIMESTAMP column(Oracle) from java class using jdbc
提问by rish1690
i have tryed many things but not able to insert data in my timestamp column. from toad its possible using this
我尝试了很多东西,但无法在我的时间戳列中插入数据。从蟾蜍它可能使用这个
UPDATE SUPPORTSTAFF
SET SUPPSTAFFJOINDATE=to_timestamp('27/02/2002 15:51.12.539880', 'dd/mm/yyyy hh24:mi.ss.ff')
where JDBCUSERID='5700';
its working
它的工作
but how can i insert data from java class using create statment and execute query its giving me invalid month error
但是我如何使用 create statment 从 java 类插入数据并执行查询它给我无效月份错误
回答by Jon Skeet
Use a PreparedStatement
with a parameter for the timestamp, e.g.
使用PreparedStatement
带有时间戳的参数,例如
UPDATE SUPPORTSTAFF SET SUPPSTAFFJOINDATE = ? where JDBCUSERID = ?
and then set the parameters:
然后设置参数:
statement.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
statement.setString(2, "your ID");
(Then execute the statement, obviously.)
(显然,然后执行该语句。)