I'm trying to use named parameter markers in a SQL query with Java and db2, like this:
SELECT ...
FROM mytable c ...
WHERE c.id_field = :myParam
I configure the connection like this:
Properties properties = new Properties(); // Create Properties object
properties.put("user", config.getDbUser()); // Set user ID for connection
properties.put("password", bdPassword); // Set password for connection
properties.put("enableNamedParameterMarkers", 1);
currentConnection = (DB2Connection) DriverManager.getConnection(config.getDbUrl(), properties);
I made a DB2PreparedStatement with the query and set the value in this way:
DB2PreparedStatement ps = (DB2PreparedStatement) currentConnection.prepareStatement(sqlString);
ps.setJccStringAtName("myParam", "value");
But I get the next error:
Error: com.ibm.db2.jcc.am.SqlSyntaxErrorException:
[jcc][10448][12695][4.19.66] Parameter marker 'myParam' was not present in the SQL String. ERRORCODE=-4461, SQLSTATE=42815
I can't guess why this is happening.
Additional data:
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2jcc</artifactId>
<version>4.19.66</version>
</dependency>
IBM Data Server Driver for JDBC and SQLJ 4.19.66
SELECT VERSIONNUMBER FROM SYSIBM.SYSVERSIONS
VERSIONNUMBER |
---|
-10050900 |
9070900 |
10050800 |
10051000 |
11010405 |
11010406 |
11050700 |