Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Time formatting issues using oracle.sql.DATE.fromText

user11079321May 18 2015 — edited May 18 2015

I am attempting to set an oracle.sql.DATE value to pass to a stored procedure, but get some odd behaviour.  Oracle 10.2 database, ojdbc7.jar (30 Jun 2014 version), JRE 1.8.0_31.  Any thoughts?

a) DATE timeslot = DATE.fromText("20150518_0942","YYYYmmdd_hh24mi",null);

This causes a stack trace:

java.sql.SQLException: Invalid Oracle Date

    at oracle.sql.LdxLibThin.ldxstd(LdxLibThin.java:1704)

    at oracle.sql.DATE.fromText(DATE.java:993)

But:

DATE timeslot = DATE.fromText("20150518_09:42","YYYYmmdd_hh24:mi",null);

works fine.  OK, so I seem to have a workaround, but why should I need the extra punctuation?

b) The following code may not produce a stack trace, but the time value is 9 hours behind the correct value:

Date timestamp = new Date();

java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyyMMdd_HHmm");

fmt.setTimeZone(TimeZone.getTimeZone("UTC"));

DATE timeslot = DATE.fromText(fmt.format(timestamp),"YYYYmmdd_hh24mi",null);

System.out.println(timeslot.timeValue());

But run later in the day, it failed in the same way...

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 15 2015
Added on May 18 2015
1 comment
652 views