如何在sybase iq中执行PreparedStatement(select object_id())? [英] How do I execute PreparedStatement(select object_id()) in sybase iq?

查看:178
本文介绍了如何在sybase iq中执行PreparedStatement(select object_id())?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个小型的jdbc应用程序,它与sybase iq数据库进行通讯,

We have a small jdbc application that talks to sybase iq database which does:

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:

We are using 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."

有人可以告诉我我做错了什么吗?谢谢.

Can someone tell me what I am doing wrong? Thank you.

推荐答案

尽管API文档可能会说些什么,但我认为参数索引必须从零开始,这可能是您正在使用的JDBC驱动程序中的错误.尝试从零开始的索引. setString(0,....);

Despite what the API doc might say, I think the parameter index must be zero-based, maybe this is a bug in the JDBC driver you are using. Try with zero-based index. setString(0,....);

这篇关于如何在sybase iq中执行PreparedStatement(select object_id())?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆