简体   繁体   English

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

[英]JTDS (Java/MSSQL) - Could not find Stored Procedure

I am using JTDS with Java to connect to a Microsoft SQL database. 我使用JTDS与Java连接到Microsoft SQL数据库。 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' ". 但是,当我运行下面的代码时,我收到一个错误“无法找到存储过程'get_queue_items'”。 I've tried prefixing 'dbo.' 我试过加上'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. 我是JTDS和Java的新手,所以我可能有错,但任何帮助都会受到赞赏。

Edit: Changed the Stored Procedure as per Cristian's advice, still getting the same error 'Could not find stored procedure 'get_queue_items' 编辑:根据Cristian的建议更改了存储过程,仍然得到相同的错误'找不到存储过程'get_queue_items'

Edit 2: Still not working - database connectivity seems fine also. 编辑2:仍然无法正常工作 - 数据库连接似乎也很好。

Today I met same problem and it seems to me that there is a bug in jTDS implementation. 今天我遇到了同样的问题,在我看来,jTDS实施中存在一个错误。 For me solution was procedure renaming and removing all underscore symbols (that is getQueueItems(?) in your case). 对我来说,解决方案是过程重命名并删除所有下划线符号(在您的情况下是getQueueItems(?) )。 Try, I think it must help to you. 试试,我认为这对你有所帮助。

you have to specify the output parameters, there are certain parameters that can not be specified as: text, ntext, and image. 您必须指定输出参数,有些参数不能指定为: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

this prodecure will return only id numbers 此prodecure将仅返回id号码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM