Two Laptop Bag
The moose likes JDBC and Relational Databases and the fly likes Parameter Index out of range ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Parameter Index out of range !" Watch "Parameter Index out of range !" New topic

Parameter Index out of range !

Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hello All
Consider the following code:

The above method is in from the Bean class and is being called from servlet. This is actually to fetch data from database and display on the browser. Am using JSP and JSTL to display on the browser. Now my problem is am getting "Parameter index out of range(2) number of parameters which is (1)" error on the tomcat console. Am not able to trace out the problem in this code. Can anyone tell me the origin of the error and how to handle it?

And one more issue is, I have given 2 queries(query1, query2) to execute. I actually wanted to combine those 2 queries to a single query but din't knew how. I mean how to combine 2 select statements? Can I write 2 separate queries to fetch data? Is my code correct?

Thanks & Regards
Swapna Gouri
I "try", I "catch" and "finally" WIN !!!
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1082

Swapna ,

I did not see code completely but give you some tips

look at your code below

For each query you should have either a separate variable of prepared statement or use then one by for each queries.

you should have something like

now when you are setting the value for place holder ? then for each prepared statement it should start from 1

I mean how to combine 2 select statements?

You should check relationship between tables, It there is any relationship available, you can use joins.


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
I agree. Here's the link:
subject: Parameter Index out of range !
It's not a secret anymore!