Solved

ResultSet getObject question?

Posted on 2002-06-18
3
759 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:xiaoxiangz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Expert Comment

by:kotan
ID: 7091497
why don't you use resultset.getBigDecimal().
0
 

Author Comment

by:xiaoxiangz
ID: 7092918
Well, in the future, the oracle table may contain
other type of fields, such date and integers.  So I want to use getObject().
0
 

Accepted Solution

by:
pothuganti_srinivas earned 150 total points
ID: 7105224
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question