Solved

ResultSet getObject question?

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now