2011-11-17 113 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