Results 1 to 6 of 6

Thread: Java & Oracle: Passing Date

  1. #1
    Join Date
    May 2008
    Posts
    248

    Java & Oracle: Passing Date

    Hello,
    I parse string into two 2 dates so far nothing too serious. The purpose of these dates is to use a sql query to an Oracle database doing tests to see if a field is in between these 2 dates.
    Code:
    prepStat.setDate(INDEX_1, new java.sql.Date(begindate.getTime().getTime()));
                prepStat.setDate(Index2, new java.sql.Date(endDate.getTime().getTime()));
    The problem is, I would like to say in my prepared statement that he should put these 2 dates in a specific format (by DD / MM / YY HH: MI: SS) and I want to initialize any of the dates at 0 and the other just before midnight. Could you advise me on track? Thank you very much.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Java & Oracle: Passing Date

    Hello,
    Especially as I know, such detail is specific to the implementation of the driver / database. In my opinion you have no control over where possible. Oracle is the driver who chooses how he stores a java.util.Date to its tables.
    To specify the hour / minute / second, it must act on the java.util.Date object that is used with Calendar:
    Code:
    Date mydate = ...;
    
    Calendar testcal = Calendar.getInstance();
    testcal.setTime(mydate);
    testcal.set(Calendar.HOUR, 0);
    testcal.set(Calendar.MINUTE, 0);
    testcal.set(Calendar.SECOND, 0);
    testcal.set(Calendar.Millisecond, 0);
    Date newDate = testcal.getTime();
    Hope this will help you

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Java & Oracle: Passing Date

    Hi
    The object is java.sql.Date DATE SQL object that represents a single date without hour / minute / second.
    For the concept of date + time you must turn to the subject timestamp. This will help you more than sticking to the current code part.

  4. #4
    Join Date
    May 2008
    Posts
    248

    Re: Java & Oracle: Passing Date

    Hello,
    I'll try with the TimeStamp object. What I do not understand is that my fields are DATE type in my sql database, but if I look at my data (with sqlDeveloper) I have hours, minutes and seconds are displayed. Does it come from the fact that all my time insertions are done using the Oracle SYSDATE? So if I send via JDBC TimeStamp objects, can-THERE compare objects date of my comics (which have many hours, minutes, seconds)? Thank you

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Java & Oracle: Passing Date

    Hi,
    Does it come from the fact that all my time insertions are done using the Oracle SYSDATE?
    Yes, it does.
    So if I send via JDBC TimeStamp objects, can-THERE compare objects date of my comics (which have many hours, minutes, seconds)?
    Yes, even here you have understood it.
    It is the object is java.sql.Date half naze ... The javadoc says it is quite telling:
    "To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with Which the instance is associated."

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Re: Java & Oracle: Passing Date

    Hello,
    In standard SQL type DATE contains only a date, type TIME contains only an hour and TIMESTAMP contains both. Objects Date, Time and Timestamp in java.sql represent these different types of weather. Now the level of the DB this can vary because they can implement their own versions and their own types. The conversion is performed during data access. But anyway, you must use the right type depending on what is desired and depending on what we base.

Similar Threads

  1. Passing by reference in Java
    By Amy Adams in forum Software Development
    Replies: 5
    Last Post: 06-04-2010, 11:17 AM
  2. Passing optional parameters in java
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 10:20 AM
  3. Message Passing in Java
    By rashmi_ay in forum Software Development
    Replies: 5
    Last Post: 25-02-2010, 10:33 PM
  4. Passing parameter of Oracle procedure in PHP
    By Halina in forum Software Development
    Replies: 3
    Last Post: 22-04-2009, 08:46 PM
  5. Problem Passing Data Dynamically in Java
    By Kushan in forum Software Development
    Replies: 3
    Last Post: 26-03-2009, 02:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,045,804.55120 seconds with 17 queries