Results 1 to 7 of 7
  1. #1
    jackjosh_in is offline Member
    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

    Default inserting date in oracle database

    Hi,
    following is the java code for parsing date
    ------------------------------------
    import java.text.SimpleDateFormat;

    String dd = "2006-10-20T1350"

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-m-d'T'HHmm");
    Date now = new Date();

    sdf.parse( dd );
    ------------------------------------
    iam getting following outptut
    Fri Jan 20 13:50:00 GMT+05:30 2006

    now i want to insert this date in oracle database column (mark as date)
    pls help

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Where you stuck with?

    Did you write a query to insert it? Are you dealing with the current date?

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by jackjosh_in View Post
    iam getting following outptut
    Fri Jan 20 13:50:00 GMT+05:30 2006
    Where does that result come from? I get:

    Java Code:
    Fri Oct 20 13:50:00 CEST 2006
    I suppose you have to fix that first.

    kind regards,

    Jos

    ps. I'm not talking about the time zone differences; look at the month ...

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Eranga View Post
    In formatting I can see that, T1350. Is that formatted in correct way?
    Note the quoted capital 'T' in the format String so yes it has the correct formatting.

    kind regards,

    Jos

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Eranga View Post
    Ok then with the testing.

    It just print the 2006-10-20T1350 on the console. So?
    Try this:

    Java Code:
    String dd = "2006-10-20T1350";
    
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HHmm");
    
    Date d= sdf.parse( dd );
    
    System.out.println(d);
    it definitely doesn't print 'Jan' (as the OP showed) but 'Oct' in the date output on my laptop.

    kind regards,

    Jos

Similar Threads

  1. Replies: 2
    Last Post: 04-01-2010, 04:35 AM
  2. Compare date input to database with current date
    By hungleon88 in forum Advanced Java
    Replies: 2
    Last Post: 11-25-2008, 08:10 AM
  3. Inserting current date into a DB table
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-15-2008, 08:38 AM
  4. PreparedStatement - inserting date
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-11-2008, 08:44 AM
  5. Inserting file in to database
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-07-2008, 08:39 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
  •