Solved

ResultSet getObject question?

Posted on 2002-06-18
3
758 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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