java - 从 JDBC 执行 Sybase 过程时出现问题

标签 java jdbc sybase jconnect

从 JDBC 执行 Sybase 过程时,出现以下错误:

Execute cursor is declared on a procedure which contains a non-SELECT or a SELECT with COMPUTE clause. for the declaration of this cursor to be legal it should have a single select statement without a compute clause



我正在使用 JCONN4 sybase jar。 sybase 是否对程序有这样的限制,没有带有计算子句的选择语句?

我也在 Sybase 文档中搜索过,但没有得到正确的答案。

http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.39996_1250/html/svrtsg/svrtsg348.htm

我不能在这里发布程序,但我可以发布示例
create proc sample (@value_date datetime = null) as
begin 
if @value_date is null 
  select @value_date  = some_column from some_table

select a,b,c,d into #ad
from 
 table_a where a='something'

select a,b,c,d case when a=0 then 0 else b/a
from #ad

end

使用 sybStatemt.executeQuery 函数调用上述过程

看起来像它的 Sybase 错误。重现问题的步骤
  • 创建一个具有 select 和计算子句的过程,如上所述
  • 编写jdbc程序并使用belew方法
    语句.setFetchSize(1000);
  • 执行程序,你会看到错误

  • 现在的问题是 Sybase 真的有这些限制,还是只针对他们的驱动程序,我们可以说它的驱动程序问题?

    最佳答案

    您必须使用 CallableStatement调用存储过程时

    If you execute a stored procedure in a CallableStatement object that represents parameter values as question marks, you get better performance than if you use both question marks and literal values for parameters. Also, if you mix literals and question marks, you cannot use output parameters with a stored procedure.

    The following example creates sp_stmt as a CallableStatement object for executing the stored procedure MyProc:

    CallableStatement sp_stmt = conn.prepareCall(   "{call MyProc(?,?)}");
    

    The two parameters in MyProc are represented as question marks. You can register one or both of them as output parameters using the registerOutParameter methods in the CallableStatement interface.

    In the following example, sp_stmt2 is a CallableStatement object for executing the stored procedure MyProc2.

     CallableStatement sp_stmt2 = conn.prepareCall(   {"call MyProc2(?,'javelin')}");
    

    关于java - 从 JDBC 执行 Sybase 过程时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61211557/

    相关文章:

    SQL - 返回具有最大创建时间戳值的数据的不同行

    java - Java 中的 Arduino Map 等效函数

    java - 如何在 onActivityResult 中获取上下文

    java - 获取方法中所有变量名

    java - 使用 Java 和 Netbeans 从我的数据库中选择计数

    hibernate - 由 : java. lang.IllegalArgumentException 引起 : java. lang.Object 不是索引实体或索引实体的子类

    sql - 提高 Sql Delete 的性能

    java - 如何使用 Spring 加载属性文件?

    java - 非常快地将多行插入 Oracle 数据库

    java - 是否可以使用 table_name.column_name 文本标签从 Oracle DB 获取列元数据?