如何执行PreparedStatement的Sybase IQ中(选择OBJECT_ID())?(H

2019-10-23 06:23发布

我们有一个小的JDBC应用程序,会谈到Sybase IQ数据库,其作用:

String objectName = "SYS.SYSWEBSERVICE"; 
//The actual value of objectName does not matter.
//It could be any view object in the sys schema

PreparedStatement preparedStatement =
    connection.prepareStatement("SELECT OBJECT_ID(?)");
preparedStatement.setString(1, objectName);
preparedStatement.executeQuery();

我们收到此错误:

java.sql.SQLException: JZ0SA: Prepared Statement: Input parameter not set, index: 0.s

我看着http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc39001.0700/html/prjdbc0700/CHDGJJIG.htm

JZ0SA: Prepared Statement: Input parameter not set, index: _____.
Action: Be sure that each input parameter has a value.

当我更改代码

setString(0, objectName)

我正进入(状态:

java.lang.ArrayIndexOutOfBoundsException: -1
    at com.sybase.jdbc4.jdbc.SybPreparedStatement.a(Unknown Source)
    at com.sybase.jdbc4.jdbc.SybPreparedStatement.a(Unknown Source)
    at com.sybase.jdbc4.jdbc.SybPreparedStatement.a(Unknown Source)
    at com.sybase.jdbc4.jdbc.SybPreparedStatement.setString(Unknown Source)

我们使用jconn-4.0.jar:

Manifest-Version: 1.0
Created-By: 1.6.0_03 (Sun Microsystems Inc.)
Main-Class: SybVersion

Name: com/sybase/jdbcx/
Implementation-Vendor: "Sybase, Inc."
Specification-Title: "jConnect for JDBC 4.0"
Implementation-Title: "com.sybase.jdbcx"
Implementation-Version: "Build (26502)"
Specification-Version: "7.0"
Specification-Vendor: "Sybase, Inc."

谁能告诉我什么,我做错了什么? 谢谢。

Answer 1:

尽管什么API文档可能会说,我觉得参数索引必须从零开始,也许这是你正在使用JDBC驱动程序中的错误。 尝试用从零开始的索引。 的SetString(0,....);



文章来源: How do I execute PreparedStatement(select object_id()) in sybase iq?