Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2007
    Location
    Bangalore, India
    Posts
    5

    Exclamation Unanswered: sqlcode -104 sqlstate 42601 Issue with JDBC Prepared Statement in DB2

    Hi,

    I am trying to create an Index on two columns of my table via Prepared Statement using JDBC in DB2 V9.7 UDB on Windows 7.

    Raw SQL in my properties file :
    Code:
    CREATE INDEX ${schemaName}.? ON ${schemaName}.? (colName1, colName2)
    Processed SQL query becomes :
    Code:
    CREATE INDEX mySchema.? ON mySchema.? (colName1, colName2)
    I use PreparedStatement to bind the parameter values such as

    Code:
    pStmt.setString(1, indexName);
    pStmt.setString(2, tableName);
    When I execute this statement, it gives an error as follows

    Code:
    sqlcode -104 sqlstate 42601 SQLERRMC=?;REATE INDEX
    I was wondering what might have caused the sql statement to get scrambled with (I see that a question mark and a semicolon got inserted somewhere).

    Whenever I ran this statement via java.sql.Statement without any parameter binding but as a hard coded one (just for testing), it worked fine without any issues.

    Any help would be highly appreciated.

    Thanks,
    Raghavan alias Saravanan Muthu.

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    debug can be activated to trace the code (I presume : not being a programmer)
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  3. #3
    Join Date
    Apr 2007
    Location
    Bangalore, India
    Posts
    5
    Quote Originally Posted by przytula_guy View Post
    debug can be activated to trace the code (I presume : not being a programmer)
    Hi Guy Przytula,

    Thanks. Can you please be a bit more specific on this? I had actually posted another question in the same DB2 forum asking how I can actually debug/print the PreparedStatement values after the binding happens.

  4. #4
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    Hi,

    you are not allowed to use the parameter markers for the table/index/column names.
    Regards,
    Mark.

  5. #5
    Join Date
    Apr 2007
    Location
    Bangalore, India
    Posts
    5
    Quote Originally Posted by mark.b View Post
    Hi,

    you are not allowed to use the parameter markers for the table/index/column names.
    I see. Thanks Mark. I suspected something to be of that nature might have caused the issue.

    I need to make it generic for an Index Creation on a table, where both table name and index name will vary at runtime. So the only other way is to use a java.sql.Statement ? Or is there any other alternatives in a better way for handling this scenario?
    Last edited by itsraghz; 08-21-15 at 04:52. Reason: general

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •