0

I'm having an error in my code,

java.lang.RuntimeException: org.postgresql.util.PSQLException: The column index is out of range: 12, number of columns: 11

I spent some time looking at different solutions but no avail.

This is my code where I have my sql string,

public void insertToDB(Active active) {

        String sql = "INSERT INTO active (branchname, branchcode, sidnew, sidold, accountno, openingbalance, "
                + "paymentreceived, currentcharges, monthlyrecrate, invoiceno, category)"
                + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        Connection conn = null;

        try {

            conn = dataSource.getConnection();
            PreparedStatement ps = conn.prepareStatement(sql);

            ps.setString(3, active.getBranchname());
            ps.setString(4, active.getBranchcode());
            ps.setString(5, active.getSidnew());
            ps.setString(6, active.getSidold());
            ps.setString(7, active.getAccountno());
            ps.setString(8, active.getOpeningbalance());
            ps.setString(9, active.getPaymentreceived());
            ps.setString(10, active.getCurrentcharges());
            ps.setString(11, active.getMonthlyrecrate());
            ps.setString(12, active.getInvoiceno());
            ps.setString(13, active.getCategory());

            ps.executeUpdate();
            ps.close();

        } catch (SQLException e) {
            throw new RuntimeException(e);

        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {}
            }
        }

    }

And here's the log from my eclipse console.

java.lang.RuntimeException: org.postgresql.util.PSQLException: The column index is out of range: 12, number of columns: 11. at com.joven.dao.ActiveDAOImpl.insertToDB(ActiveDAOImpl.java:74) at com.joven.core.ActiveAccountsReadExcel.getExcelInfo(ActiveAccountsReadExcel.java:138) at com.joven.core.ActiveAccountsReadExcel.ValidateExcelFormat(ActiveAccountsReadExcel.java:56) at com.joven.core.ActiveAccountsReadExcel.buttonChooseFile(ActiveAccountsReadExcel.java:41) at com.joven.ui.MainView$3.handle(MainView.java:110) at com.joven.ui.MainView$3.handle(MainView.java:1) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) at javafx.event.Event.fireEvent(Event.java:198) at javafx.scene.Node.fireEvent(Node.java:8413) at javafx.scene.control.Button.fire(Button.java:185) at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182) at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96) at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89) at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) at javafx.event.Event.fireEvent(Event.java:198) at javafx.scene.Scene$MouseHandler.process(Scene.java:3757) at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485) at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762) at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:432) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431) at com.sun.glass.ui.View.handleMouseEvent(View.java:555) at com.sun.glass.ui.View.notifyMouse(View.java:937) Caused by: org.postgresql.util.PSQLException: The column index is out of range: 12, number of columns: 11. at org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.java:56) at org.postgresql.core.v3.SimpleParameterList.setStringParameter(SimpleParameterList.java:118) at org.postgresql.jdbc2.AbstractJdbc2Statement.bindString(AbstractJdbc2Statement.java:2310) at org.postgresql.jdbc2.AbstractJdbc2Statement.setString(AbstractJdbc2Statement.java:1398) at org.postgresql.jdbc2.AbstractJdbc2Statement.setString(AbstractJdbc2Statement.java:1384) at org.apache.commons.dbcp.DelegatingPreparedStatement.setString(DelegatingPreparedStatement.java:135) at org.apache.commons.dbcp.DelegatingPreparedStatement.setString(DelegatingPreparedStatement.java:135) at com.joven.dao.ActiveDAOImpl.insertToDB(ActiveDAOImpl.java:67) ... 49 more

Any help is appreciated. Thanks!

3
  • 3
    Your query has only 11 ? placeholders, you can't call ps.setString with an index > 11 . Commented Mar 1, 2017 at 8:05
  • Superb! I thought my ps.setString with indexes are the position in PostgreSQL table. Thank you! How do I accept it as answer? Commented Mar 1, 2017 at 8:28
  • I added this as an answer below. Commented Mar 1, 2017 at 8:30

1 Answer 1

1

Your query has only 11 ? placeholders, you can't call ps.setString with an index bigger than 11.

The possible values range from 1 to 11 in your case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.