大家好,欢迎来到IT知识分享网。
异常:java.sql.SQLException: 无效的列索引
解决办法:删除SQL语句字符串中‘?’两边的引号
原SQL语句字符串:
修改后的SQL语句字符串:
异常发生在用java连接数据库对数据库进行操作的过程中,
异常信息:
java.sql.SQLException: 无效的列索引
at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:5168)
at oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:5156)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.setString(OraclePreparedStatementWrapper.java:246)
at com.dlf.deallogin.LoginDAO.dealLogin_2(LoginDAO.java:54)
at org.apache.jsp.processlogin_jsp._jspService(processlogin_jsp.java:129)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
由于这是个低级错误,就不做过多解释了。
以下该异常的解决办法摘自2020/5/7-笔记:”java.sql.SQLException: 无效的列索引”异常的解决
无效的列索引”其实是个低级的错误,原因无非几个:
1、sql串的?号数目和提供的变量数目不一致:
例如:jdbcTemplate.update(sql, new Object[] {newState,oldState});
如果sql里面有1个?号,Object[]送了2个,就会报错。
2、sql串里的?号书写不正确
英文?和中文?有时难以区分。
3、sql串的?号用”括了起来。
例如:sql=”UPDATE abc SET abc.name=’?’ WHERE abc.id=’?'”;
把”去掉就可以了。
4,遇到这种情况select*from user where info like %?%;
虽然这是sql的写法,但是在jdbc 中需要改成 select*from user where info like ?;
如ps.setString(“%”+value+“%”);
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/27622.html