0

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();

We are getting this error:

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

I looked at 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.

When I change the code

setString(0, objectName)

I am getting:

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)

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.

user674669
  • 10,681
  • 15
  • 72
  • 105
  • My answer was based off the error reporting index: 0 as the problem, since the api you linked suggests otherwise could you also include the value of `objectName` as it may be relevant. –  Jun 03 '15 at 22:49
  • Thanks @Phaeze. I updated my question. – user674669 Jun 03 '15 at 22:59
  • Most of the thigns that come up on google regarding that specific error are pointing at a versioning difference with JConnect between the app and the sybase server. Have a look at: http://tech.forums.softwareag.com/techjforum/posts/list/47520.page –  Jun 03 '15 at 23:08
  • 1
    Sounds like a bug in the driver. – Mark Rotteveel Jun 04 '15 at 06:23

1 Answers1

-1

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,....);

Mirko Klemm
  • 2,048
  • 1
  • 23
  • 22