Skip to main content

Solved: The index 1 is out of range.

This error usually comes when we try to insert data in a query where there is no index defined for it.

Example :-

String strQuery=“select * from location where city_id=? ”;

The question mark will be the the first index if we want to insert data so if we call a function like-

oPreparedStatement = oConnection.prepareStatement(strQuery);


here we are sending 235 as a first parameter so it will work fine but as soon as we write something after it like


then it will throw “The index 2 is out of range” since there is no place to send this value in a query hence it will throw the same error. Here index defines the parameter for which there is no place in the query.

To rectify this we need to write query like-

String strQuery=“select * from location where city_id=? And city_name=? ”;

then it will work fine.

The cases in which these errors can occur is-

1)Query is coming out as null.
2)No of parameters are more than the parameters present in the query.
3)The index for which we are trying to send parameter is not present in the query.

4)There is not any ways applied in a query to receive parameters( absence of ?).



Popular posts from this blog

Topics to Start - preparing for Data Structures and Algorithms

Learn in a different way :- Strings stacks and queues heaps searching hash table sorting recursion dynamic programming greedy algorithms graphs tree Binary Search Tree Linked List Array Parallel programming and concurrency design problems system design availability and scalability  Below topics are good to have object oriented programming language details ( java , python) object oriented design tools ( bash , git , maven , jira , jenkins , docker , kubernetes) database

Best LeetCode Lists for Interviews

Here is a list of some of the best questions asked in interviews:-  Must do 75 Must do 60 Must do medium:- Must do Easy:- Graph:-  Dynamic Programming:-  FaceBook interviews:-  Amazon Interviews:-  Google Interviews:-