Convert JAXB XMLGregorianCalendar to java.sql.Date

Discussion in 'Java' started by puneet.maini@gmail.com, Mar 5, 2007.

  1. Guest

    Hello,

    Do you know of a way to convert
    javax.xml.datatype.XMLGregorianCalendar
    --- to ---
    java.sql.Date.


    I'm parsing (unmarshalling) an xml doc using JAXB api, and I need to
    save the date i'm getting from xml into the database.

    Does anyone know of a possible way of doing this.

    Thanks in advance.
     
    , Mar 5, 2007
    #1
    1. Advertising

  2. kgorthi

    Joined:
    Apr 16, 2009
    Messages:
    1
    I know you must have been set with the issue by now. Just posting it here for anyone having the same question:

    Try this:

    XMLGregorianCalendar xcal = <assume this is initialized>;
    java.util.Date dt = xcal.toGregorianCalendar().getTime();

    To get a SQL version Date:
    java.sql.Date sqlDt = new java.sql.Date(dt.getTime());
     
    kgorthi, Apr 16, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,358
    Michael Borgwardt
    May 30, 2004
  2. Replies:
    5
    Views:
    98,840
    vongeuca
    May 4, 2011
  3. Replies:
    5
    Views:
    5,661
  4. grz01
    Replies:
    3
    Views:
    2,415
    Arne Vajhøj
    Sep 18, 2009
  5. bw
    Replies:
    8
    Views:
    1,133
    Tom Anderson
    Jan 31, 2011
Loading...

Share This Page