Skip to main content

Solved: com.microsoft.sqlserver.jdbc.SQLServerException: 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);

oPreparedStatement.setString(1,235);

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

oPreparedStatement.setString(2,”kanpur”)

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 ?).

Comments

.

Popular posts from this blog

Adding Node at the End of Linked List

Adding Node at the End of Linked List:- The method takes two parameter one a head node of a linked list and other data too insert. public void addNodeEnd ( Node head , int data ) { if ( head == null ) { System . out . println ( "list is empty" ); return ; } Node node = new Node ( data ); Node temp = head ; while ( temp . next != null ) { temp = temp . next ; } temp . next = node ; } To Know the basic structure of the linked list click here

DEPTH FIRST SEARCH IN JAVA

DEPTH FIRST SEARCH IN JAVA public void dfs () { vertex [ 0 ]. visited = true ; displyVertex ( 0 ); stackobj . push ( 0 ); while (! stackobj . isEmpty ()) { int v = adjVertex (( Integer ) stackobj . peek ()); if ( v ==- 1 ) { stackobj . pop (); } else { vertex [ v ]. visited = true ; displyVertex ( v ); stackobj . push ( v ); } } }