ResultSet getObject question?

Hi, I am using  ResultSet.getObject method to
retrieve Oracle data through JDBC .  If I use
getString , it works.  But when I use getObject
, I got all null.  The data type in Oracle table is number, the responding java data type should be
BigDecimal.

Thanks.
Sean
xiaoxiangzAsked:
Who is Participating?
 
pothuganti_srinivasConnect With a Mentor Commented:
If you want a generic piece of code to work for different data types, you can do a small check before retreiving the data from result set using ResultSetMetaData.getColumnType() and code accordingly so that it does not break if some other data types are there in the database.

The code could be like this

if(resultSet.getMetaData().getColumnType(1)==java.sql.Types.DECIMAL){
   Object obj = resultSet.getBigDecimal(1);

}

......

0
 
kotanCommented:
why don't you use resultset.getBigDecimal().
0
 
xiaoxiangzAuthor Commented:
Well, in the future, the oracle table may contain
other type of fields, such date and integers.  So I want to use getObject().
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.