This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC 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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Parameter Index out of range !" Watch "Parameter Index out of range !" New topic
Author

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: 1081

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.


Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
 
 
subject: Parameter Index out of range !
 
Similar Threads
Data Alignment
SQLException:Parameter Index out of Range
Problem in inserting from one table to another
Getting NPE !
Control not entering the while loop !