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
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);
Java Code:Timestamp ts = new Timestamp(date. getTime()); Above example command will return the current timestamp and save values in ts object variable.
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.
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.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With