我正在将JTDS与Java连接到Microsoft SQL数据库。我能够完美地连接到数据库。但是,当我运行下面的代码时,出现错误“找不到存储过程'get_queue_items'”。我尝试在'dbo'前面加上前缀。到存储过程名称,但是我继续收到错误消息。我还提供了实际的存储过程以供参考。

try {
    // Prepare and call the stored procedure
    CallableStatement proc = connection.prepareCall("{call get_queue_items(?) }");

    // Register the ResultSet
    proc.registerOutParameter(1, java.sql.Types.INTEGER);

    // Register Input Parameters
    proc.setInt("@last_queue_entry", 1);

    // Execute the stored procedure
    proc.execute();

    // If we have a ResultSet
    if (proc.getMoreResults()) {
        ResultSet rs = proc.getResultSet();
        if (rs.next()) {
            // to complete...
        }
    }
}
catch(Exception ex)
{
    System.out.println("Error: " + ex.getMessage());
}


和存储过程:

USE [test]
GO
/****** Object:  StoredProcedure [dbo].[get_queue_items]    Script Date: 11/17/2011 11:43:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[get_queue_items] @qid int OUT, @last_queue_entry int as
-- select all the new records out of the main table into a temp table
-- the temp table is what we will use to process

select @qid = qid from test.[dbo].que_items
where qid > @last_queue_entry


我是JTDS和Java的新手,所以可能是我的错,但是任何帮助都将不胜感激。

编辑:根据克里斯蒂安的建议更改了存储过程,仍然得到相同的错误“找不到存储过程'get_queue_items'

编辑2:仍然无法正常工作-数据库连接似乎也很好。

最佳答案

今天,我遇到了同样的问题,而且在我看来jTDS实现中存在一个错误。对我来说,解决方案是重命名过程并删除所有下划线符号(在您的情况下为getQueueItems(?))。试试吧,我认为它必须对您有所帮助。

10-06 13:14
查看更多