如何使用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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 05:00:15  来源:igfitidea点击:

How to insert Current time in TIMESTAMP column(Oracle) from java class using jdbc

oraclejdbctimestamp

提问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 PreparedStatementwith 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.)

(显然,然后执行该语句。)