Results 1 to 3 of 3
  1. #1
    sasi.tati is offline Member
    Join Date
    Jul 2010
    Posts
    18
    Rep Power
    0

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

    :confused: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?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    While the information about your db and code is lacking, I will ask why you need more than the the first date update...am/pm is already stored in the original Date object you used to call setDate, it just needs to be formatted when retrieved.

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

Similar Threads

  1. insert data from text field to jtable
    By mackinas in forum New To Java
    Replies: 2
    Last Post: 06-09-2010, 04:30 AM
  2. insert java code to SQL
    By rashidzamani in forum JDBC
    Replies: 3
    Last Post: 08-18-2009, 01:07 PM
  3. Insert oracle rowtype
    By Faheem_Ahmed in forum New To Java
    Replies: 0
    Last Post: 02-28-2009, 07:12 AM
  4. Replies: 1
    Last Post: 10-10-2008, 08:47 AM
  5. How to insert java Object in oracle database
    By Thilkumar82 in forum Advanced Java
    Replies: 9
    Last Post: 08-13-2008, 11:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •