Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 482
rish1690 Avatar asked May 01 '13 13:05

rish1690


People also ask

How do I add a timestamp to a column in Oracle?

You can use the below code: insert into tablename (timestamp_value) values (TO_TIMESTAMP(:ts_val, 'YYYY-MM-DD HH24:MI:SS')); If you need the current timestamp to be inserted then use the following code: insert into tablename (timestamp_value) values (CURRENT_TIMESTAMP);

How do I return a timestamp in Java?

Java Code:Timestamp ts = new Timestamp(date. getTime()); Above example command will return the current timestamp and save values in ts object variable.

What is timestamp format in Java?

A Timestamp also provides formatting and parsing operations to support the JDBC escape syntax for timestamp values. The precision of a Timestamp object is calculated to be either: 19 , which is the number of characters in yyyy-mm-dd hh:mm:ss. 20 + s , which is the number of characters in the yyyy-mm-dd hh:mm:ss.

What is the datatype for timestamp in Oracle?

Introduction to Oracle TIMESTAMP. Oracle TIMESTAMP is a data type which stores in the format of century, Year, Month, Date, Hour, Minute, Second. TIMESTAMP is an extension of DATE data type. TIMESTAMP data type is an enhancement of DATE data type and provides more intelligence.


1 Answers

Use a PreparedStatement with a parameter for the timestamp, e.g.

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.)

like image 129
Jon Skeet Avatar answered Oct 05 '22 03:10

Jon Skeet