2011-11-17 107 views
0

我正在使用带有Java的JTDS连接到Microsoft SQL数据库。我能够完美地连接到数据库。但是,当我运行下面的代码时,出现错误“无法找到存储过程get_queue_items'”。我已经尝试在'dbo'前缀。到存储过程名称,但是我继续得到错误。我还包含了实际的存储过程以供参考。JTDS(Java/MSSQL) - 找不到存储过程

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:还没工作 - 数据库连接似乎罚款也。

回答

2

今天我遇到了同样的问题,在我看来,有在JTDS实现中的错误。对我而言,解决方案是重命名过程并删除所有下划线符号(即您的案例中为getQueueItems(?))。试试,我认为这对你有帮助。

0

您必须指定输出参数,但某些参数不能指定为: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 

这prodecure将返回唯一的ID号

+0

我完全按照上面的方法修改了程序,但仍然得到相同的错误。 – MichaelICE

+0

**连接**连接到数据库[测试]? –

+0

如果我将此行修改为此CallableStatement proc = connection.prepareCall(“{call [test]。[dbo]。[get_queue_items](1)}”); 并删除参数会给出错误错误:过程或函数'get_queue_items'需要参数'@last_queue_entry',它没有提供。 – MichaelICE