Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQLException Invalid Descriptor Index

 
salman moin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
highR = reccheck.getFloat("HIGHEST");
Above is my coding accessing a field value, I got an error message "Invalid Descriptor Index".
Can any one help me resolve this error
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you provide more of the code body? A description of the table to which the SQL statement is going against and the actual SQL statement would be helpful.
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After you get the resultset, did you check if it has next?
while(result.next()){
//do you getXXX() here
}
 
salman moin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok below is the coding:
ResultSet reccheck("SELECT * FROM STK_DETAIL WHERE STK_ID = '" + f2 + "'");
int highR = reccheck.getFloat("HIGHEST");
please also tell me how to resolve the invalid cursor state problem thanx...
 
salman moin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Tran:
Can you provide more of the code body? A description of the table to which the SQL statement is going against and the actual SQL statement would be helpful.

Resultset reccheck = statement.executeQuery("SELECT * FROM STK_DETAIL WHERE STK_ID = '" + f2 + "'");
int highR = reccheck.getFloat("HIGHEST");
at the above line i got the problem...
do you have any idea about it?
 
Anand Joshi
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please make sure
1. Field 'HIGHEST' exists in table STK_DETAIL
2. There are some records in the in the table STK_DETAIL which matches the selection criteria
Here I found interesting thing in the selection criteria
(STK_ID = '" + f2 + "'")
what is f2 doing?
I think you need to create PreparedStatement and you need to use
setString method to provide values of f2.
I hope it will help.
3. Make sure there are records in the resultset.
Regards
 
salman moin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anand
f2 is a string type variable which i have checked that contain the right value.
HIGHEST exist in table STK_DETAIL
There are few records in the table and one thing I forgot to tell that my application is running well with MS Access 2000.
This error only occurs when I connect to SQL Server.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to do a reccheck.next() after the executeQuery(). Until you do a next(), you are not pointing to any rows in the table.
 
titojermaine
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a very similar problem as this. I am attaching to SQL-Server 7.0 and getting a similar error when I attempt to retreive columns of a numerical data type (tinyint, smallint, int, etc.). I am able to retreive columns of the varchar data type without a problem, even in the same recordset, on the same record. I'm also using string concatentation within the SQL queries (this is a temporary fix until I have a chance to write stored procedures, which may contribute to solving or intensifying the current issue...) throughout the application without any problems elsewhere, so I do not believe that is the issue. If I find a solution to the issue I'm having, I will post it. For now, the only other suggestion I could offer is to use System.out.println to dump out your query to the screen after the string concatenation has occurred. Copy and paste it into MS-SQL Query Analyzer, and be sure the query itself is not the cause of the issue (it's likely not to be at this point, but it's worth a try).
 
titojermaine
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After a little more research on the web, I was able to solve my issue, but the solution may apply to this issue as well. It seems that we're gonna have to thank the good people of Microshaft for this one. Basically, suppose you have a query like the one listed here:
SELECT col1, col2, col3
FROM table
The exception occurs when you try to access the columns out of the order that they were queried in. That means that if you use one of the get...() functions to retrieve each column, you have to be careful the order you retrieve them in. If you get col2 first, you cannot get col1 any longer, but if you get col1 before you get col2, it will be fine. Basically, just check the order that you are getting the columns in, and make sure that order matches the order in the query.
However, in the example given in this thread, it is selecting * (which might make the ordering confusing, but it's the ordering of the columns in the table at this point), and only one column has been obtained at the time of the exception, so perhaps the solution I suggested here may not be a straightforward solution, but hopefully it'll give you some new ideas.
 
Charlie Boss
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its 11:57pm here.. i'm still at work yes.. i've been working on this same problem since 8 this morning.. i can't tell u how much i'm grateful.. thank you.. thank you.. whew..
 
Jaha Cush
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the help. I have been working on this for 5 hours and I could not figure it out. You are the greatest.
Regards,
Jaha
Originally posted by titojermaine:
After a little more research on the web, I was able to solve my issue, but the solution may apply to this issue as well. It seems that we're gonna have to thank the good people of Microshaft for this one. Basically, suppose you have a query like the one listed here:
SELECT col1, col2, col3
FROM table
The exception occurs when you try to access the columns out of the order that they were queried in. That means that if you use one of the get...() functions to retrieve each column, you have to be careful the order you retrieve them in. If you get col2 first, you cannot get col1 any longer, but if you get col1 before you get col2, it will be fine. Basically, just check the order that you are getting the columns in, and make sure that order matches the order in the query.
However, in the example given in this thread, it is selecting * (which might make the ordering confusing, but it's the ordering of the columns in the table at this point), and only one column has been obtained at the time of the exception, so perhaps the solution I suggested here may not be a straightforward solution, but hopefully it'll give you some new ideas.

 
David Grant
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tito, thanks a lot. I had only been working on this problem for about 3 minutes but your information was enough to fix it. Thanks again-
david
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic