#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    26
    Rep Power
    0

    inserting date into Oracle!


    Hi,

    I have been trying to insert the current date into ORACLE with my JSP for the past 1 day in vain...

    my query reads like this..

    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("dd/MM/yyyy");
    java.util.Date currentTime_1 = new java.util.Date();
    String dateString = formatter.format(currentTime_1);

    out.println( "<br>" );
    out.println( dateString ); // shows current date Fine..

    sql = "INSERT into RESERV_DOC_UPD(CODE,DOC_COD,COLAB_COD,RESERVED,DATE_RESERV)";

    sql += "VALUES("+temp+","+code+","+COLAB_COD+","+RESERVED+","+(to_date(dateString, dd/mm/yyyy))+")";

    Can anyone Please tell me whats wrong with this query and the remedy for it!!???

    Thnx a lot in adv,

    gaucho
  2. #2
  3. No Profile Picture
    Java Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Posts
    5
    Rep Power
    0
    Hi,

    There are 2 ways you can do this:
    1) set the date on the statement
    2) pass in a string and use oracle to parse the date

    I don't like using 1, but have in the past. 2 is what you seem to be doing, but you've got the quotes in the wrong place, as the to_date function is part of oracle, so you want to put that as part of your query string and only put the dateString as variable...

    sql += "VALUES("+temp+","+code+","+COLAB_COD+","+RESERVED+", (to_date("+dateString+", dd/mm/yyyy)))";

    Any help?

    Oscagne
  4. #3
  5. No Profile Picture
    Java Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Posts
    5
    Rep Power
    0
    oh yeah, and in oracle you can just call the system variable SYSDATE, which contains the curren date. So you could have...

    sql += "VALUES("+temp+","+code+","+COLAB_COD+","+RESERVED+", SYSDATE)";

    Oscagne
  6. #4
  7. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    26
    Rep Power
    0
    ABSOULTELY!!

    Thnx!!

IMN logo majestic logo threadwatch logo seochat tools logo