Take the 2-minute tour ×

I use Prepared statements in Oracle SQL query. I have problem which I don't know how to solve.

I want to set timestamp like using this:

ps.setTimestamp(36, null); 

The problem is that I don't know what parameter to set in order to execute timestamp into Oracle? How I must replace null in my case?

share|improve this question
Either that's a package in which case what is the code or it's a different language, in which case what is it? –  Ben Dec 18 '12 at 20:38
This code will be used in Java. –  user1908169 Dec 18 '12 at 20:39
You need to post a lot more code. I assume that you're using setTimestamp - docs.oracle.com/javase/1.4.2/docs/api/java/sql/…, java.sql.Timestamp) to add a parameter to a prepared statement. What is the statement? The 36th index here means that it is the 36th parameter you want to add? Is this correct? –  Ben Dec 18 '12 at 20:44
36 params?!? Ever considered JPA? Also, you need to learn to consult the API when you have a java question. As the answer by @JacobASeverson points out, the API answers you question quickly. That should always be the first place you go with any java questions. –  jahroy Dec 18 '12 at 21:57
add comment

2 Answers

up vote 2 down vote accepted

This example sets a Timestamp value to the current time (with precision to milliseconds):

Timestamp ts = new Timestamp(new Date().getTime());
ps.setTimestamp(36, ts);

If you also need nanoseconds you can set those separately:

ps.setTimestamp(36, ts);
share|improve this answer
add comment

If you look at the method in the PreparedStatement class, you need to create a TimeStamp object that you will replace your null with.

share|improve this answer
+1 for referring OP to the API (which makes the answer obvious). This should always be step 1 when trying to solve a java issue! –  jahroy Dec 18 '12 at 21:56
add comment

Your Answer


