This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes getObject() method is not returning the proper result. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "getObject() method is not returning the proper result." Watch "getObject() method is not returning the proper result." New topic
Author

getObject() method is not returning the proper result.

meenakshi gavhale
Greenhorn

Joined: Apr 13, 2012
Posts: 8
hi,

i m using getObject(int paramInt) of ResultSet.

so when i m firing select sysdate from dual on database
and try to retrieve result with resultset.getObject(1);

i get different results for jdk1.5 and 1.6
for jdk1.5 i got only Date
and for jdk 1.6 i got date and time both
this is because while retrieving result in jdk 1.5 sysdate is object of Date at runtime
in jdk1.6 it is an object of timestamp
so is there any solution to change it in jdk1.5 as an object of timestamp because because want to use jdk 1.5 and also need result date with time both

do reply..........
thanks in advanced
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Welcome to the Ranch, meenakshi!

Using resultset.getTimeStamp() should work in both versions of Java. I'd suggest not to use the resultset.getObject() at all, always use getter for the concrete type instead. It will prevent this kind of surprises from happening.
meenakshi gavhale
Greenhorn

Joined: Apr 13, 2012
Posts: 8
ya i know i can use getTimestamp()

but i m retrieving different objects in my code with this getObject() so i can not use getTimestamp()
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

It seems to me that you've generalized your code so much it's hurting you. I've done that in the past too, the best way out is to "ungeneralize" it a bit, in my opinion.

You could at least try to pass additional information about column types to your generalized method, and this method could use this information to call getTimestamp() instead of getObject(), if the column was DATE.
meenakshi gavhale
Greenhorn

Joined: Apr 13, 2012
Posts: 8
ya i did the same thing in code
but i thought something more efficient i have to do
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

This very same thing was discussed yesterday, I made a very good suggestion in that thread, I am to lazy to type it again.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: getObject() method is not returning the proper result.
 
Similar Threads
sqlException : "Invalid scale size. Cannot be less than zero." when executing script with UNION
getObject() method is not returning the proper result.
Classes12 or ojdbc14.jar ?
Difference of JAVA 1.6 and JAVA 1.5
Timestamp.compareTo() problem with jdk1.5