java.sql.SQLException: Invalid column index while inserting data

java.sql.SQLException: Invalid column index while inserting data

invalid column index in oracle stored procedure
java.sql.sqlexception: invalid column name
java.sql.sqlexception: invalid column type
invalid column index in adf
boomi invalid column index
java sql sqlexception invalid parameter index 1
jdbc column index
caused by: java sql sqlexception

I am trying to insert values into a table, but it always throws "java.sql.SQLException: Invalid column index". I had verified the column indexes as per my knowledge. Below is what I tried.

stmt = con.prepareStatement("insert into test_table(ASSESMENT_YEAR,ASSESMENT_MON,CODE,KRA_CODE,BASE_VALUE,ACTUAL_VALUE,USERNAME,CHANGE_DATE)"
                + "values (?,?,?,?,?,?,?,SYSDATE)");

        stmt.setInt(1, Calendar.getInstance().get(Calendar.YEAR));
        stmt.setInt(2, Calendar.getInstance().get(Calendar.MONTH));
        stmt.setString(3, getcode(dm.getStr1(), dm.getStr2())); 
        stmt.setString(4, dm.getStr4());
        stmt.setInt(5, dm.getNum1());
        stmt.setInt(6, dm.getNum2());
        stmt.setString(7, "admin");

The above is throwing error in the 4th stmt. But if I hardcode the values as below, data gets properly inserted.

        stmt.setInt(1, 2018);
        stmt.setInt(2, 12);
        stmt.setString(3, "1111"); 
        stmt.setString(4, "0000");
        stmt.setInt(5, 12);
        stmt.setInt(6, 1);
        stmt.setString(7, "admin");

Any help would be appriciated!!

Edit: Below is the stacktrace

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.dao.KRADataDao.addData(KRADataDao.java:59)
    at com.service.Controller.service(Controller.java:56)
    at com.service.Dispatcher.service(Dispatcher.java:25)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:625)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1372)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

The Below segment is also not working :

        stmt.setInt(1, Calendar.getInstance().get(Calendar.YEAR));
        stmt.setInt(2, Calendar.getInstance().get(Calendar.MONTH));
        stmt.setString(3, getcode(dm.getStr1(), dm.getStr2())); 
        stmt.setString(4, "0000");
        stmt.setInt(5, dm.getNum1());
        stmt.setInt(6, dm.getNum2());
        stmt.setString(7, "admin");

It could be a reuse of stmt. Use the try-with-resources syntax for a local instance, automatically closed, even on exception:

try (PreparedStatement stmt = con.prepareStatement("insert into test_table"
            + "(ASSESMENT_YEAR,ASSESMENT_MON,CODE,KRA_CODE,BASE_VALUE,ACTUAL_VALUE,"
            + "USERNAME,CHANGE_DATE)"
            + "values (?,?,?,?,?,?,?,SYSDATE)")) {
    stmt.setInt(1, Calendar.getInstance().get(Calendar.YEAR));
    stmt.setInt(2, Calendar.getInstance().get(Calendar.MONTH));
    stmt.setString(3, getcode(dm.getStr1(), dm.getStr2())); 
    stmt.setString(4, dm.getStr4());
    stmt.setInt(5, dm.getNum1());
    stmt.setInt(6, dm.getNum2());
    stmt.setString(7, "admin");

    stmt.executeUpdate();
}

My guess is that in getcode the reuse of stmt happens.

In general always use local variables, try-with-resources. Some PreparedStatements might benefit from a longer scope, but with fixed SQL, and the name then should not be stmt.

Invalid column index exception while inserting into the DB, if you access column data using incorrect column name, JDBC will throw "java.​sql.SQLException: Invalid column name" while if index is incorrect JDBC will throw "  Main reason of SQLException:Invalid Column Index is either you are trying to read an invalid column index from result set returned by Query or you are setting parameter on parametric prepared Statement on invalid index using getString or setString method. usually this comes when programmer uses index "0" to refer first element which is not true


If the column does not exist, or you must enter the stmt.executeUpdate(); statement.

How to fix java.sql.SQLException: Invalid column index, SQLException: Invalid column index" When "NORDER" is Used As a Bind Variable. INSERT INTO SXML_ELEMENT values (1,123);. INSERT  JDBC 11.2.0.1.0 Throws "java.sql.SQLException: Invalid column index" When "NORDER" is Used As a Bind Variable (Doc ID 1092429.1) Last updated on MARCH 10, 2019


I don't know what database system you are using. So please verify that CODE is not a reserved word / keyword.

In that case please rename the third column and try again.

"java.sql.SQLException: Invalid column index" When "NORDER", I am trying to insert values into a table, but it always throws "java.sql.​SQLException: Invalid column index". I had verified the column indexes as  First let's discuss java.sql.SQLException: Invalid column index and solve it in java. --Before executing java program execute these database scripts > create table EMPLOYEE(ID number(4), NAME varchar2(22));


java: java.sql.SQLException: Invalid column index while inserting data, When i am running the program , the error i am getting is invalid column index java.sql.SQLException: Invalid column index at oracle.jdbc.dbaccess.DBError. Add another data item to current row. String y = "INSERT INTO convert(ToDate,​Time,Badge,System,Comments,Device,Temp,Status) VALUES(?,?,?,?,?,?,?,?)"; Yeah, but the problem is my SQL statement is fine. When I run it directly in the DataBase it grabs exactly want. There aren't any errors being show in the Dataset Query Dialog either.


java SQLException:Invalid column index-URGENT!!!!! Solutions , java.sql.SQLException: Invalid column index. please help me out the application have two tables. i will show them and while saving the form i am encountering one more error: java.sql.SQLException: ORA-00913: too many values insert into hsemonthly_report1(bgroup,bvertical,pvertical,site,months  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more java.sql.SQLException: Invalid column index while inserting data


java.sql.SQLException: Invalid column index, SQLException: Invalid column index often occurs in ADF when your ADF View After adding the new Table column to your Entity Object and View Object the following error occur at runtime : java.sql java.sql.SQLException: Invalid column index at oracle.jdbc.driver. Learn how your comment data is processed​. I'm trying to make insertion in Oracle Db using prepared statement but it is giving me this exception : " java.sql.SQLException: Invalid column index", i searched in the forum all doing select or update no one making insertion .so i cant find what's wrong .