预准备语句中的“无效列索引”异常

时间:2017-01-06 11:37:52

标签: java sql jdbc prepared-statement

我在预准备语句中编写了一个insert语句,并使用列索引添加了参数。但是当我执行时,我将异常作为“无效列索引”。我没有得到我做错了什么。请帮我解决这个问题。

代码段:

public boolean insertAttachment(Map<String, String> AttachRecord, String RequestID) throws Exception{
        int updateLastID = 0;
        String query = "INSERT INTO mashups.ts_attachments"
                        +"(ts_id, ts_parentid, ts_nextid, ts_previd, ts_fldid, ts_caseid,"
                        +"ts_authorid, ts_time, ts_type, ts_srctableid, ts_desttableid,"
                        +"ts_subtype, ts_destrecid, ts_lastaccess, ts_sequence,"
                        +"ts_accesstype, ts_title, ts_mimetype, ts_filename, ts_contents,"
                        +"ts_versionid, ts_checkedoutuser, ts_ischeckedout,"
                        +"ts_isspattachment)"
                        +" values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";


        try {
            pstmt = con.prepareStatement(query);
            pstmt.setInt(1, this.getLastID("ts_attachments"));
            pstmt.setString(2, AttachRecord.get("TS_PARENTID"));

            pstmt.setString(3, AttachRecord.get("TS_NEXTID"));
            pstmt.setString(4, AttachRecord.get("TS_PREVID"));
            pstmt.setString(5, AttachRecord.get("TS_FLDID"));
            pstmt.setString(6, RequestID);
            pstmt.setString(7, AttachRecord.get("TS_AUTHORID"));
            pstmt.setString(8, AttachRecord.get("TS_TIME"));
            pstmt.setString(9, AttachRecord.get("TS_TYPE"));
            pstmt.setString(10, AttachRecord.get("TS_SRCTABLEID"));
            pstmt.setString(11, AttachRecord.get("TS_DESTTABLEID"));
            pstmt.setString(12, AttachRecord.get("TS_SUBTYPE"));
            pstmt.setString(13, AttachRecord.get("TS_DESTRECID"));
            pstmt.setString(14, AttachRecord.get("TS_LASTACCESS"));
            pstmt.setString(15, AttachRecord.get("TS_SEQUENCE"));
            pstmt.setString(16, AttachRecord.get("TS_ACCESSTYPE"));
            pstmt.setString(17, AttachRecord.get("TS_TITLE"));
            pstmt.setString(18, AttachRecord.get("TS_MIMETYPE"));
            pstmt.setString(19, AttachRecord.get("TS_FILENAME"));
            pstmt.setString(20, AttachRecord.get(RequestID+"TS_CONTENTS"));
            pstmt.setString(21, AttachRecord.get("TS_VERSIONID"));
            pstmt.setString(22, AttachRecord.get("TS_CHECKEDOUTUSER"));
            pstmt.setString(23, AttachRecord.get("TS_ISCHECKEDOUT"));
            pstmt.setString(24, AttachRecord.get("TS_ISSPATTACHMENT"));

            pstmt.execute();

            updateLastID = this.updateLastID("ts_attachments");

            this.insertResource(AttachRecord.get("TS_CONTENTS"), AttachRecord.get(RequestID+"TS_CONTENTS"));
        } catch (SQLException e) {
            con.rollback();
            // TODO Auto-generated catch block
            //e.printStackTrace();
            throw e;

        }

        return true;
    }

例外:

java.sql.SQLException: Invalid column index
    at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:5386)
    at oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:5374)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.setString(OraclePreparedStatementWrapper.java:282)
    at com.nvenergy.serena.dao.PostAttachmentsDAO.insertAttachment(PostAttachmentsDAO.java:128)
    at com.nvenergy.serena.dao.PostAttachmentsDAO.copyAttachmnets(PostAttachmentsDAO.java:100)
    at com.nvenergy.serena.action.PostAttachmentsImpl.postAttachments(PostAttachmentsImpl.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:256)
    at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:121)
    at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
    at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:106)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:169)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:176)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:163)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

0 个答案:

没有答案