0

I'm trying to use named parameter markers as in:

SELECT field
FROM table
WHERE field = :value  -- I'd like to use this ':value'

I've been reading about this and I understood that I need to convert my PreparedStatement to a DB2PreparedStatement, and I did, by including also this dependency in my pom.xml:

    <dependency>
        <groupId>com.ibm.db2</groupId>
        <artifactId>db2jcc</artifactId>
        <version>8.1</version><!-- I was using 4.3.111 before -->
    </dependency>

But then I come to Eclipse and try, but it doesn't seem to detect the setJccXXX() method in the DB2PreparedStatement and I can't get it to compile.

method not detected

I also read that I can make my custom code for a Statement through inheritance, but I wouldn't likw to reinvent the wheel if I can make this work.

My main suspect is that this could be something about the version of db2jcc, but I think this is the highest version I can use from the repositories I'm allowed to use.

Additional data:

At the terminal: $ java -cp /full/path/to/db2jcc4.jar com.ibm.db2.jcc.DB2Jcc -version

IBM DB2 JDBC Universal Driver Architecture 2.3.63

At the database:

SELECT VERSIONNUMBER FROM SYSIBM.SYSVERSIONS

|VERSIONNUMBER| 
|-------------| 
|-10050900 | 
|9070900 | 
|10050800 | 
|10051000 |
|11010405 | 
|11010406 | 
|11050700 |
madtyn
  • 1,469
  • 27
  • 55
  • Have you tried `com.ibm.db2.jcc.DB2PreparedStatement ps = (com.ibm.db2.jcc.DB2PreparedStatement) IDataSgaFacade.getPreparedStatement(sqlString)` as described in [Using named parameter markers with PreparedStatement objects](https://www.ibm.com/docs/en/db2/11.5?topic=applications-using-named-parameter-markers-preparedstatement-objects)? – Mark Barinstein Mar 31 '22 at 07:51
  • Yes, I'm doing that inside the getPreparedStatement() method – madtyn Mar 31 '22 at 08:23
  • What's your db2 jcc driver version? – Mark Barinstein Mar 31 '22 at 08:41
  • It's in the maven dependency in the post. It's the 8.1 – madtyn Mar 31 '22 at 09:11
  • 1
    It's not a [Db2 jcc driver](https://www.ibm.com/support/pages/db2-jdbc-driver-versions-and-downloads) version. What's the result of `java -cp /full/path/to/db2jcc4.jar com.ibm.db2.jcc.DB2Jcc -version` for the jar file you use? – Mark Barinstein Mar 31 '22 at 09:26
  • @MarkBarinstein IBM DB2 JDBC Universal Driver Architecture 2.3.63 – madtyn Mar 31 '22 at 09:43
  • If you really work with this very old Db2 8.2.0 (aka 8.1.7) version (which is not supported for 13 years already), then this driver probably doesn't support named parameters at all. If not, then you should use jcc driver which corresponds to your Db2 Server version. You may run the following to check it: `SELECT VERSIONNUMBER FROM SYSIBM.SYSVERSIONS` – Mark Barinstein Mar 31 '22 at 10:03
  • |VERSIONNUMBER| |-------------| |-10050900 | |9070900 | |10050800 | |10051000 | |11010405 | |11010406 | |11050700 | – madtyn Mar 31 '22 at 10:17
  • You work with Db2 11.5.7 - the latest Db2 version and fixpack. You must not work with this version with your so old current driver. So, download the corresponding Db2 jcc driver version 4.31.10 at the link above and use it instead. – Mark Barinstein Mar 31 '22 at 10:29
  • I was using at the beginning db2jcc-4.3.111 and it was the same, but I'm trying now with the version you just told me – madtyn Mar 31 '22 at 10:35
  • Great! I tried with 4.19.66 which was the maximum version available at my allowed repositories, and it seems to work. Thank you very much! You may post your answer and get the credit. – madtyn Mar 31 '22 at 10:47

1 Answers1

1

Seems, that this very old Db2 jcc 2.3.63 version driver (from Db2 V8.2) doesn't have support for named parameters.
Contemporary Db2 jcc drivers do support such a functionality.
It's strongly advised to use Db2 jcc drivers corresponding to the Db2 Server version.

Mark Barinstein
  • 11,456
  • 2
  • 8
  • 16