Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Java & Oracle: Passing Date

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 04-01-2010
Member
 
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.

Reply With Quote
  #2  
Old 04-01-2010
Member
 
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
Reply With Quote
  #3  
Old 04-01-2010
Member
 
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.
Reply With Quote
  #4  
Old 04-01-2010
Member
 
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
Reply With Quote
  #5  
Old 04-01-2010
Member
 
Join Date: May 2008
Posts: 2,297
Re: Java & Oracle: Passing Date

Hi,
Quote:
Does it come from the fact that all my time insertions are done using the Oracle SYSDATE?
Yes, it does.
Quote:
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."
Reply With Quote
  #6  
Old 04-01-2010
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Java & Oracle: Passing Date"
Thread Thread Starter Forum Replies Last Post
Passing by reference in Java Amy Adams Software Development 5 06-04-2010 11:17 AM
Passing optional parameters in java Miles Runner Software Development 5 05-03-2010 10:20 AM
Message Passing in Java rashmi_ay Software Development 5 25-02-2010 10:33 PM
Passing parameter of Oracle procedure in PHP Halina Software Development 3 22-04-2009 08:46 PM
Problem Passing Data Dynamically in Java Kushan Software Development 3 26-03-2009 02:26 PM


All times are GMT +5.5. The time now is 05:54 PM.