Index 2 is out of range :(

I have the following code in java

qry="insert into usr_auth(usrid,username,password,email) values(?,?,?,?)";


this code gives me IndexOutOfBoundsException


Database Exception

We are sorry for the inconvenience

Exception Details: Index 2 is out of range. Details:

Index 2 is out of range.

Stack trace: index 2 missing assortment. at ( at (SQLServerPreparedStatement) in (SQLServerPreparedStatement) ( at ( at DBOps.addUser ( at ( .servlet.http.HttpServlet.service ( at javax.servlet.http.HttpServlet.service ( at org.apache.catalina.core.ApplicationFilterDoChain.internalF:30 ) in org.apache.catalina.core.ApplicationFilterChain.doFilter ( at org.apache.catalina.core.StandardWrapperValve.invoke ( at org.apache.catalina.core.StandardContextValve.invoke ( .catalina.authenticator.AuthenticatorBase.invoke ( at org.apache.catalina.core.StandardHostValve.invoke ( at org.apache.catalina.valves.ErrorinReportValve (ErrorValve. : 100) at org.apache.catalina.valves.AccessLogValve.invoke ( at org.apache.catalina.core.StandardEngineValve.invoke ( at org.apache.catalina.connector. CoyoteAdapter.service ( at org.apache.coyote.http11.Http11AprProcessor.process ( at org.apache.coyote.http11.Http11AprProtocol $ Http11.ConnectionConnectionprocess ( in $ ( in java.util.concurrent.ThreadPoolExecutor $ Worker.runTask (Unknown Source) in java. util.concurrent.ThreadPoolExecutor $ (Unknown Source) at (Unknown Source)

In the database I have 4 columns usrid, username, password, email

username is of type nvarchar(MAX)


Everything seems fine, but I am still getting this exception, why? [Line 55 in the stacktrace is ps.setString (2, newUp.getUsrName ());]


source to share

1 answer

Not directly related to your problem, but you can get this error if you miss a single quote somewhere when using XQuery in SQL. I had it with the following SQL:

UPDATE TABLE SET CustomFields.modify('replace value of (/CustomFields/Field[@ID=1]/Value)[1] with "HELLO WORLD!") WHERE ID=?


It should be

UPDATE TABLE SET CustomFields.modify('replace value of (/CustomFields/Field[@ID=1]/Value)[1] with "HELLO WORLD!"') WHERE ID=?


(no single quote after "HELLO WORLD!")

So the exception in my case was the wrong exception thrown by the SQL driver.



All Articles