Home > Software design >  Named Parameter Markers in JDBC and DB2
Named Parameter Markers in JDBC and DB2

Time:03-31

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 |

CodePudding user response:

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.

  • Related