aspose file tools*
The moose likes JDBC and the fly likes why get different result in different java version Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "why get different result in different java version" Watch "why get different result in different java version" New topic
Author

why get different result in different java version

ameng lai
Greenhorn

Joined: Aug 15, 2003
Posts: 3
my database is Microsoft SQL 2000

the database field's type is datetime

my JDBC driver is JTurbo or i-net

I get this field value through calling getTime() in java code.

my question is :

if I run my program in jdk1.3 ,I can get right minute value ,but if run same program in jdk1.4.2
I can not get right minute value.

for example :
in database execute query ,and get result :

realOffdutyDate
----- -------------------
1900-01-01 08:06:00.000

run program in jdk1.3:
get minute : 6

run program in jdk1.4.2:
get minute : 11
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

How do you get the minute-value?
What do the javadocs for 1.3/ 1.4 say?


http://home.arcor.de/hirnstrom/bewerbung
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Post some code snippets.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

one thing to be notice that getMinutes() has been deprecated in Date Class in 1.4.

so if you write rs.getDate() in JDK 1.4 will get only date Part not time part.

and as Adeel said please put some code snippet

thanks


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29246
    
139

Shailesh,
getMinutes() is deprecated because you are supposed to use Calendar.get(Calendar.MINUTES) instead. This is the first I hear of the actual precision changing. Do you know where you read that? It seems like a mighty big change for Sun who doesn't like to change semantics.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Jeanne,

I know getMinutes () has been deprecated as we are supposed to use Calendar.

and regarding precision changing

This can be individual experience, but I have moticed it few days back
and made this conclusion.

now before posing this reply I have tested same again

my environment details are

JDK 1.5
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production

I have created a table having a column date type




and results are below



might be I am missing something.
[ February 08, 2005: Message edited by: Shailesh Chandra ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Shailesh,
Getting similar using jdk1.4.2, oracle 10g, oracle thin driver.
[ February 08, 2005: Message edited by: Adeel Ansari ]
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Originally posted by Adeel Ansari:

It may help.



adeel didn't get you

help for what :roll:
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Shailesh Chandra:
adeel didn't get you
help for what


Shailesh,
I just deleted that because you got confused. However, It was for others. The first sentence is offcourse directed to you. But no worries now there is only one sentence.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

thx adeel


I got one link for this.
[ February 08, 2005: Message edited by: Shailesh Chandra ]
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Shailesh Chandra,

Regarding your issue with rs.getDate()... java.sql.Date doesn't include the time part, use getTimestamp() (check spelling, I usually mess up the case on TimeStamp/Timestamp).
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29246
    
139


Shailesh,
This really tests what Date.toString() returns. Ideally this would be the same as the precision, but it doesn't have to be.

From the JavaDoc (it's the same in 1.3, 1.4 and 1.5):
A thin wrapper around a millisecond value that allows JDBC to identify this as a SQL DATE. A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.

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.

So it sounds like Date was never supposed to include the hours/minutes/seconds and it was fixed more recently.
ameng lai
Greenhorn

Joined: Aug 15, 2003
Posts: 3
Thanks Jeanne Boyarsky ,

your quote is right.

I do this test as folowing:
step 1 : execute SQL clause , making field realOffdutyDate value is
2005-01-01 08:06:00.000
step 2 : running program in jdk1.3 and jdk1.4, ang get correct result.

I think the genuine reason is that
"A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT"

as Jeanne Boyarsky's quote



 
It is sorta covered in the JavaRanch Style Guide.
 
subject: why get different result in different java version
 
Similar Threads
jboss versioning problem
Weblogic portal upgrade from 7.0 to 9.2
client jvm problem
Reading date from Oracle based on calendar
Confusion on ejb client and jdk versions