Java w/ SQL Server Express 2008 - 索引超出范围异常

发布于 2024-08-31 02:32:44 字数 2214 浏览 3 评论 0原文

我在 sqlexpress 2008 中创建了一个存储过程,从 Java 方法调用该过程时出现以下错误:

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)

我无法弄清楚它来自哪里...>_<;

任何帮助将不胜感激。

问候, BS_C3


这是一些源代码:

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;
}

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

[旋木] 2024-09-07 02:32:44

没有提供足够的源代码来确定,但根据堆栈跟踪,我的赌注是?占位符和提供的参数数量不匹配。我的猜测是你没有足够的占位符。我建议您仔细检查以确保每个数量都正确。

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.

小矜持 2024-09-07 02:32:44

这可能是 Microsoft SQLServer JDBC 驱动程序的一个已知问题造成的。请参阅 Microsoft 知识库中的这篇文章:

文章 ID:919568:修复:当您使用转义单引号为 SQL Server 2005 JDBC 驱动程序中的预准备语句设置参数值

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

轮廓§ 2024-09-07 02:32:44

非常感谢您的回答和时间。

我必须更改数据库中的存储过程,并且在重写代码时错误消失了。

我想肖恩·赖利是对的=)

问候。
BS_C3

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文