Results 1 to 7 of 7
  1. #1
    hungleon88 is offline Member
    Join Date
    Aug 2008
    Posts
    41
    Rep Power
    0

    Default Problem when insert Date to database(SQL)

    When i insert a record with Date to database , it include Month/Day/year and something stupid like 00:00:00
    how can we remove 00:00:00 ??
    or how can we only insert month/day/year??

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Change the way you're displaying it?

    Use getDate rather than getString?

  3. #3
    hungleon88 is offline Member
    Join Date
    Aug 2008
    Posts
    41
    Rep Power
    0

    Default

    the problem here is i use method getvalueAt of DefaultModelTable , and this method return an Object , so i cannot casting to Date type :((
    and when i display it, it include 00:00:00

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Quote Originally Posted by hungleon88 View Post
    the problem here is i use method getvalueAt of DefaultModelTable , and this method return an Object ,
    And? What do you think a Date is? Cottage Cheese? A Date is also an Object, did you even try to cast it?

    so i cannot casting to Date type :((
    And, did you even try?

    and when i display it, it include 00:00:00
    Then what you are printing is either a Date (with no time data) or a String. With a Date, no problem, just cast it, with a String, no problem, use SimpleDateFormat, and parse it. If what you had were actually an instance of "Object" (as you claim) then it would print something like "java.lang.Object@d9f9c3", and not any kind of date/time text.


    Show the code you're using (only the relevant parts please, not some novel). And, please, don't tell me you have all sorts of persistence and business logic code tied up in the middle of your GUI code.
    Last edited by masijade; 12-02-2008 at 07:56 AM.

  5. #5
    neeraj.singh is offline Member
    Join Date
    Feb 2009
    Location
    Delhi
    Posts
    63
    Rep Power
    0

    Default

    we have defferent date format methods
    you can use that...
    for date at backend side
    use
    to_date(date_var, 'yyyy/mm/dd')

  6. #6
    satkk is offline Member
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default re:

    I got this code working, try this, dont know whether its the right approach
    String datestring= some string(getText() or getParameter())
    java.util.Date dt=new java.util.Date();
    java.sql.Date dte=new java.sql.Date(dt.getTime());
    java.sql.Date dte1=dte.valueOf(datestring);
    insert this dte1 to database

  7. #7
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    That code just adds a random timestamp to the date, which is probably not what you want to do. If your data includes times then include them, of not, leave the time as 00:00:00.

    All Date objects include a timestamp. If you don't want to see it, then only print the date part.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

Similar Threads

  1. Compare date input to database with current date
    By hungleon88 in forum Advanced Java
    Replies: 2
    Last Post: 11-25-2008, 08:10 AM
  2. Replies: 1
    Last Post: 10-10-2008, 08:47 AM
  3. How to insert java Object in oracle database
    By Thilkumar82 in forum Advanced Java
    Replies: 9
    Last Post: 08-13-2008, 11:33 AM
  4. Probeleme with insert into database oracle
    By bachtoutou in forum New To Java
    Replies: 0
    Last Post: 05-24-2008, 11:56 AM
  5. Replies: 0
    Last Post: 02-10-2008, 11:25 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
  •