aspose file tools*
The moose likes JDBC and the fly likes Time getting truncated in Weblogic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Time getting truncated in Weblogic" Watch "Time getting truncated in Weblogic" New topic
Author

Time getting truncated in Weblogic

praveenreddy dinnapaty
Greenhorn

Joined: Sep 18, 2007
Posts: 6
I am using getDate() of ResultSet in my program and I am not able to retrieve the time portion of the date . I have 5/28/2008 5:51:23 PM in my DB and when I use resultSet.getDate() I am getting only 5/28/2008.\
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

ANSI SQL's date data type doesn't hold any time information. To match this behaviour java.sql.Date strips out the hours, minutes, seconds and milliseconds. Use a java.sql.Timestamp instead.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
praveenreddy dinnapaty
Greenhorn

Joined: Sep 18, 2007
Posts: 6
Thanks for the reply .I have tried resultset.getTimestamp also but I am not able to get the time portion ....The code is working fine in Tomcat ...When I deploy it on weblogic I am losing the time portion..

please help me
Pete Ihlenfeldt
Greenhorn

Joined: Jan 24, 2008
Posts: 9
I assume that you are certain the database field is of type datetime. If you are uncertain (i.e. if you did not do the database implementation or do not have direct access) you can check using the ResultSetMetaData class:

(after calling rs = stmt.executeQuery()...)


if you are sure it is, then you should be able to get the full timestamp using



That doesn't work?
praveenreddy dinnapaty
Greenhorn

Joined: Sep 18, 2007
Posts: 6
we are using Date for the database column instead of DateTime ....Do we have to change the column to datetime or is there a way to get the time portion with date column ?

please help me
Pete Ihlenfeldt
Greenhorn

Joined: Jan 24, 2008
Posts: 9
Which database are you using (want to know before I respond)?
praveenreddy dinnapaty
Greenhorn

Joined: Sep 18, 2007
Posts: 6
We are using oracle 10g....
Pete Ihlenfeldt
Greenhorn

Joined: Jan 24, 2008
Posts: 9
Ok, I believe you may have to convert that field to a TIMESTAMP in order for it to register with querying drivers as a field that contains both Date and Time portions. 10g also has TIMESTAMP WITH TIME ZONE and TIMESTAMP WITH LOCAL TIMEZONE types, but I'll leave that determination to you.

TIMESTAMP is an extension of the DATE datatype, designed to include the additional information. Technically the DATE datatype in Oracle does store time information, but I believe the standardized solution for you is to make the datatype universally visible as a date/Time structure. The ANSI literal for DATE does not include time information ('2008-05-28'), so you end up having to use special Oracle-specific functions (TO_DATE) to specify time information. You don't want to do that. You want your application to be as portable as possible. TIMESTAMP also offers further granularity. DATE's time information only goes down to the second. TIMESTAMP to the millisecond. Better for determining intervals between operations recorded inside of a second.

If you want to read a little more, see...
http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/sql_elements001.htm
Find the text "DATE Datatype" and read that and the "TIMESTAMP Datatype" below it.

I think if you use TIMESTAMP, and then use the code I posted earlier, you'll be good to go. I almost always have time fields in business objects declared as java.sql.Timestamp for this very reason.

Good luck... let me know if you have anything else.
nomad
 
Consider Paul's rocket mass heater.
 
subject: Time getting truncated in Weblogic