com.microsoft.sqlserver.jdbc.SQLServerException: The index 2 is out of range :(

Prophet

Disciple
[font=Arial,]I have following code in java[/font]

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

			ps=con.prepareStatement(qry);

			ps.setString(1,getUniqueID());

			ps.setString(2,newUp.getUsrName());

			ps.setString(3,newUp.getPwd());

			ps.setString(4,newUp.getEmail());

			ps.executeUpdate();

[font=Arial,]this code is giving me an IndexOutOfBoundsException as:[/font]


Database Exception Occured

We are sorry for inconvenience

Exception Details: com.microsoft.sqlserver.jdbc.SQLServerException: The index 2 is out of range. Details:

The index 2 is out of range.

Stack Trace:

com.microsoft.sqlserver.jdbc.SQLServerException: The index 2 is out of range. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setterGetParam(SQLServerPreparedStatement.java:700) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setValue(SQLServerPreparedStatement.java:709) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setString(SQLServerPreparedStatement.java:1034) at DBOps.addUser(DBOps.java:55) at RegUser.doPost(RegUser.java:13) at javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:403) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:286) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:272) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1730) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

[font=Arial,]In database I have 4 columns usrid, username, password, email[/font]

[font=Arial,]username is of nvarchar(MAX) type.[/font]

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

[font=Arial,]You can find this question here also: http://adf.ly/6REqk[/font]
 
Back
Top