Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getObject() method is not returning the proper result.

 
meenakshi gavhale
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya i did the same thing in code
but i thought something more efficient i have to do
 
Wendy Gibbons
Bartender
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This very same thing was discussed yesterday, I made a very good suggestion in that thread, I am to lazy to type it again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic