2

I created a stored procedure in a sql express 2008 and I'm getting the following error when calling the procedure from a Java method:

Index 36 is out of range.
com.microsoft.sqlserver.jdbc.SQLServerException:Index 36 is out of range.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setterGetParam(SQLServerPreparedStatement.java:698)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setValue(SQLServerPreparedStatement.java:707)
    at com.microsoft.sqlserver.jdbc.SQLServerCallableStatement.setString(SQLServerCallableStatement.java:1504)
    at fr.alti.ccm.middleware.Reporting.initReporting(Reporting.java:227)
    at fr.alti.ccm.middleware.Reporting.main(Reporting.java:396)

I cannot figure out where it is coming from... >_<

Any help would be appreciated.

Regards, BS_C3


Here's some source code:

public ArrayList<ReportingTableMapping> initReporting(
        String division,
        String shop,
        String startDate,
        String endDate)
{
    ArrayList<ReportingTableMapping> rTable = new ArrayList<ReportingTableMapping>();

    ManagerDB db = new ManagerDB(); 
    CallableStatement callStmt = null;
    ResultSet rs = null;
    try {
         callStmt = db.getConnexion().prepareCall("{call getInfoReporting(?,...,?)}");
         callStmt.setString("CODE_DIVISION", division);
         .
         .
         .
         callStmt.setString("cancelled", " ");

         rs = callStmt.executeQuery();
         while (rs.next())
         {
             ReportingTableMapping rtm = new ReportingTableMapping(
                     rs.getString("werks"), ... );

             rTable.add(rtm);
         }
         rs.close();
         callStmt.close();

    } catch (Exception e) {
          System.out.println(e.getMessage());
          e.printStackTrace();
    } finally {
          if (rs != null)
                try { rs.close(); } catch (Exception e) { }
          if (callStmt != null)
                try { callStmt.close(); } catch (Exception e) { }
          if (db.getConnexion() != null)
                try { db.getConnexion().close(); } catch (Exception e) { }
    }   

    return rTable;
}
1
  • 1
    You're doing something with an array. Need java code to be of any help. Commented Apr 30, 2010 at 17:40

3 Answers 3

8

There isn't enough source code provided to be sure, but based on the stack trace, my bet is the number of ? placeholders and the number of parameters provided don't match. My guess is that you don't have enough placeholders. I'd suggest double-checking to make sure you have the right number of each.

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

Comments

0

This could be the result of a known problem with Microsoft's SQLServer JDBC driver. See this article in the Microsoft Knowledge Base:

Article ID: 919568: FIX: You may receive an error message when you use an escaped single quotation mark to set a parameter value for a prepared statement in the SQL Server 2005 JDBC Driver

Comments

0

Thanks a lot for your answers and time.

I had to change the stored procedure in the DB and when rewriting the code the error went away.

I guess that Sean Reilly was right =)

Regards. BS_C3

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.