I have following code in java
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();
this code is giving me an IndexOutOfBoundsException
as:
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)
In database I have 4 columns usrid, username, password, email
username is of nvarchar(MAX)
type.
Everything seems fine but I am still getting this exception why?? [The line 55 in stacktrace is the line ps.setString(2,newUp.getUsrName());]
1条答案
按热度按时间q5iwbnjs1#
与您的问题没有直接关系,但如果您在SQL中使用XQuery时在某处遗漏了一个单引号,则可能会出现此错误。
必须如此
(“HELLO WORLD!”后缺少单引号)
因此,在我的例子中,异常是SQL驱动程序抛出的错误异常。