?
Solved

Oracle JDBC driver givin problems when reading a LONG from the oracle database !!!

Posted on 2003-03-02
16
Medium Priority
?
369 Views
Last Modified: 2011-09-20
Hi,

I am reading a resultset in a usual manner by doing the while(resultset.next()) method.

I get an "ArrayIndexOutOfBoundsException" when the driver is reading the "LONG" type of value returned by the PLSQL procedure.

Again the problem is that when I am returning the LONG column as the first in the select there is no error, but when I change the position of the LONG column in the select the exception starts occuring from that line. And again its ArrayOutOfBoundsException.

I hv pasted the code below..
------------
while(rsDocs.next()){
dID = rsDocs.getString(1);
stat = rsDocs.getString(2);
dTypeCode = rsDocs.getString(3);
suppD = rsDocs.getString(4);
pNum = rsDocs.getString(5);
rDate = rsDocs.getString(6);
sNote = rsDocs.getString(7);
cNum = rsDocs.getString(8);
strSer = rsDocs.getString(9);
}
--------------
Here I am reading the LONG as the 7th column (sNote). It throws the exception.
Even if I comment that line
----------------
//sNote = rsDocs.getString(7);
----------------
I start to get the exception on the next statement.

So I have guessed that the problem is when the driver reads the LONG value from the DB and not when it is read from the resultset.

But the question remains, What/Why the problem ??
And on top of it, why not when the column is the 1st column selected !!!

Any explanations ???

Thanks,
Kaustubh.
0
Comment
Question by:kaustubhpatil
[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
  • 4
  • 3
  • 2
  • +5
16 Comments
 

Expert Comment

by:ampathak
ID: 8055342
Can you give the select statement here, so that the things will get more clearer
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 8055407
As you said, 7th parameter is LONG, so, you should use proper get method to extract that, probably this will work:-


rsDocs.getBigDecimal(7)
0
 
LVL 92

Expert Comment

by:objects
ID: 8055425
does your rs actually have 9 columns?
0
Independent Software Vendors: 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!

 
LVL 4

Expert Comment

by:boxy73
ID: 8055646
Perhaps you don't have 9 columns, or your SQL statement is not properly formed for this second try.

Anyway, when working, I suggest you should use rsDocs.getLong(7) to retrieve a Long value (never getString).

0
 

Author Comment

by:kaustubhpatil
ID: 8055662
OK,
I will clarify all your doubts.
Yes, my resultset actually has 9 coulumns. I have checked it using the ResultSetMetadata.
I cannot get the value using the getBigDecimal() or anything because a "LONG" value in the PLSQL actually is a alphanumeric and not numeric. So it has to be reterived using getString().
!!!!
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 8055724
try using getObject()
0
 

Author Comment

by:kaustubhpatil
ID: 8055781
Using getObject doesn't help.
As I said in my first post evenif I coomment out the column that is giving problem the exception is thrown from the next statement.
So whatever is used to read from the resultSet, or even if the value from the resultset is never used the program still gives exception on the next line....
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 8055814
Can you post the code which you are using to execute the stored procedure?
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 200 total points
ID: 8087629
Its always better to use the names of the table-attributes in getString () or getLong (). For example, if the name of that long attribute (column-name) in your table is "LongAttribute" and let's say that you have a string attribute "StringAttribute", then simply write:


long longValue ;
String str ;

while ( resultset.next () )
{
  str = resultset.getString ( "StringAttribute" ) ;
  longValue = resultset.getLong ( "LongAttribute" ) ;
  ....
  ....

} // end while


getString (), getLong (), getInt (), getDate (), etc are all overloaded.

Mayank.
0
 

Expert Comment

by:CleanupPing
ID: 9058970
kaustubhpatil:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9058995
Recommendation: Accept mayankeagle's comment as answer :-)
0
 
LVL 92

Expert Comment

by:objects
ID: 9062985
I doubt your answer will fix it.
More likely kaustubhpatil does not have enough placeholders included in his sql string.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9063001
Hi objects.... its been a long while! Well, I know that my solution might or might not help.... that's why I left the smiley after it :-) anyway, by now he must've fixed it!

Cheers,
Mayank.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9721237
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split between objects and mayankeagle.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TimYates
EE Cleanup Volunteer
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9721770
Please go ahead.
0

Featured Post

Technology Partners: 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

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

764 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