[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ResultSet getObject question?

Posted on 2002-06-18
3
Medium Priority
?
764 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 450 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

825 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