3 Replies Latest reply: Jul 4, 2013 5:47 PM by rp0428 RSS

    Invalid column index

    936666

      Hi,

      I am getting " Invalid column index" in java based stored procedure

          String resString;

           String resString  = ("ABCEDFG");

           byte[] splitLenArray = {1,1,1,1,1,1,1};

        int startIndex = 0;

          try

        {

        Connection conn = DriverManager.getConnection("jdbc:default:connection:");

      String sql1 = "INSERT INTO Tablename values (?,?,?,?,?,?,?) ";

      PreparedStatement pstmt = conn.prepareStatement(sql1);

      for (int len : splitLenArray)

          {

        resString= getSubString(str, startIndex, len);         

               pstmt.setString(startIndex+1, resString);

        startIndex += len;

          }   

      pstmt.executeUpdate();

         pstmt.close();

        }

        catch (SQLException e)

        {

         System.err.println(e.getMessage());

      }

      Thanks

       

      " Invalid column index"

        • 1. Re: Invalid column index
          rp0428

          >

          I am getting " Invalid column index" in java based stored procedure

          >

          And yet you didn't actually post the EXACT exception that you are getting. The stack trace will tell you exactly what line number the exception occurs on.

           

          And if you print out the index values that you are using you will see why you are getting that exception.

           

          Don't be afraid of breaking Java by actually TRYING things.

          • 2. Re: Invalid column index
            936666

            {

              resString= getSubString(str, startIndex, len);        

                     pstmt.setString(startIndex+1, resString);

                    System.out.println(resString);

                     System.out.println(startIndex+1);

              startIndex += len;

                }  

             

            A

            1

            B

            1

            C

            1

            Invalid column index

            it is printing the value till startindex of 3, after that for 4th and 5th it not printing..

            • 3. Re: Invalid column index
              rp0428

              Quit TELLING us what you THINK is happening and post the EXACT results of what IS happening.

               

              You still haven't posted the EXACT exception and stack trace that you are getting.

               

              And what you did post shows that 'startIndex' is NEVER being incremented since all printed values are '1'. The only way that can be based on what you just posted is in 'len' is ZERO. But since you never bothered to print 'len' we have NO idea what it's value is.

               

              There are NO shortcuts. You have to trace through the code (e.g. using NetBeans) to see what is actually happening or print out variable values that show what is happening.