6

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

2
  • Show us the Java code. Commented May 1, 2013 at 13:54
  • its done THanks a lot for fast responce .follwed jon's answer .now its working. Commented May 1, 2013 at 14:13

1 Answer 1

23

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

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks a lot Jon ..you saved my day. was trying from last 4 hour. this was my first question to stackoverflow which was answered in 1 min .awesome.. Just love it
Jon, what about Oracle DB ? I tried this on my oracle 11g and I get an ORA-01461: can bind a LONG value only for insert into a LONG column.
@GaëlOberson: That comment doesn't really give enough information - it's not clear where LONG comes into it at all. It sounds like it's worth asking a new question.
@Jon Not really. I have a TIMESTAMP COLUMN in my table, I use a preparded statement and set the column value like in your example, getting the oracle exception i mention.
@Telebh: I suggest you ask a new question with a minimal reproducible example. That isn't enough information on its own.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.