Skip to Main Content

Java Programming

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!

How to insert/update Date field in Oracle with java code

807580Jul 28 2010 — edited Jul 28 2010
Dear All

I have to insert/update a date column while creating a new item, but the problem is i am able to insert/update only date but i need both date and time along with AM/PM.

By using these 3 lines i am able to insert/update only date.
java.util.Date date = new java.util.Date();
long dateLong = date.getTime();
stmtPrep.setDate(33, new java.sql.Date(dateLong));

Below code retrives the date exactly what i need but unable to pass in the statement:
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss a");
java.util.Date d = (Date) new java.util.Date();
String stringdate = formatter.format(d);
String tmpdate = dateFormat();
stmtPrep.setString(33, tmpdate); -- I tried with setObject as well but same error coming.

Error is:
ORA-01830: date format picture ends before converting entire input string

Can u guide me how to get full date time with AM/PM?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 25 2010
Added on Jul 28 2010
3 comments
13,283 views