1

We have a Java webapp that talks to an Oracle database. We are keeping track of a particular time (timestamp format in Oracle) and we were wondering what would be the best time format in java to use.

The database we are talking to could be in the US or Europe so we need a java type that will allow us to use Locales.

What in peoples opinion would be the best Java type to use?

2 Answers 2

7

You should use java.sql.Timestamp together with a PreparedStatement then you don't need to worry about a "format" at all.

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

4 Comments

Can java.sql.Timestamp have a Local specified?
You don't need a Locale when using Timestamp it is stored without any "formatting". Formatting should be done when displaying the value in the frontend not when storing it in the database. I hope your "timestamp" column is not actually a varchar column!
@Damo: Do you mean Locale or local time zone? Locale is relevant only to formatting timestamp as text. As for local time zone, java.sql.Timestamp is agnostic of that. It is just a long number inside. The timezone-related magic happens in the JDBC driver. With Oracle TIMESTAMP WITH TIME ZONE you should be all set.
its not no but you had me looking there
2

What is the datatype of the Oracle field that you are storing timestamp?

Make sure it preserves timezone data.

1 Comment

That's good! If you'd used just TIMESTAMP, it would have been interpreted in the session time zone and Oracle JDBC driver is setting session timezone according to the time zone of your JVM, which might be different than the time zone where that timestamp came from.

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.