JTDS (Java/MSSQL) - 找不到存储过程

发布于 2024-12-17 04:13:49 字数 1428 浏览 1 评论 0原文

我使用 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 的新手,所以很可能是我的错,但任何帮助将不胜感激。

编辑:按照 Cristian 的建议更改了存储过程,仍然收到相同的错误“无法找到存储过程 'get_queue_items'”

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

I am using JTDS with Java to connect to a Microsoft SQL database. I am able to connect to the database perfectly. However when I run the code below, I am getting an error "Could not find stored procedure 'get_queue_items' ". I've tried prefixing 'dbo.' to the stored procedure name, however I continue to get the error. I've also included the actual stored procedure for reference.

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

And the stored procedure:

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

I'm new to JTDS and Java, so its likely I am at fault, but any help would be appreciated.

Edit: Changed the Stored Procedure as per Cristian's advice, still getting the same error 'Could not find stored procedure 'get_queue_items'

Edit 2: Still not working - database connectivity seems fine also.

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

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

发布评论

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

评论(2

绻影浮沉 2024-12-24 04:13:49

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

Today I met same problem and it seems to me that there is a bug in jTDS implementation. For me solution was procedure renaming and removing all underscore symbols (that is getQueueItems(?) in your case). Try, I think it must help to you.

失退 2024-12-24 04:13:49

您必须指定输出参数,有些参数不能指定为:text、ntext 和 image。

ALTER procedure [dbo].[get_queue_items] @id 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 @id = id from test.[dbo].que_items
where qid > @last_queue_entry

该程序将仅返回 id 号

you have to specify the output parameters, there are certain parameters that can not be specified as: text, ntext, and image.

ALTER procedure [dbo].[get_queue_items] @id 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 @id = id from test.[dbo].que_items
where qid > @last_queue_entry

this prodecure will return only id numbers

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