JTDS (Java/MSSQL) - 找不到存储过程
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
今天我遇到了同样的问题,在我看来,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.您必须指定输出参数,有些参数不能指定为:text、ntext 和 image。
该程序将仅返回 id 号
you have to specify the output parameters, there are certain parameters that can not be specified as: text, ntext, and image.
this prodecure will return only id numbers