JDBC PreparedStatement with setObject(int, null) causing SQLException
Details
| Detail name | Value |
|---|---|
| Changelog Number | 24032 |
| Type | Bug |
| Status | Resolved |
| Affected Versions | Exasol 7.1.0, JDBC 24.0.0 |
| Fix Versions | JDBC 25.2.3 |
| Resolution Date | 2025-04-11 |
Description
When a PreparedStatement is created with multiple parameters and the JDBC driver needs to set the value for a parameter N, it initially creates DummyColumn placeholders for any unset parameters. If an intermediate parameter is set to null, this triggers an SQLException.
Example:
try {
// Create JDBC Connection
// Create Schema and Table with columns C1 DECIMAL(10, 0), C2 VARCHAR(100), C3 DECIMAL(10, 0)
try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO TABLE (C1, C2, C3) VALUES (?, ?, ?)")) {
stmt.setInt(1, 1); // Creates column at index 0
stmt.setInt(3, 1); // Creates column at index 2 and DummyColumn at gap index 1
stmt.setObject(2, null); // sets null on DummyColumn
stmt.executeUpdate();
}
} catch (SQLException ex) {
...
}
Observed Error:
java.sql.SQLException: Invalid parameter data type received from client for parameter 2. Parameter type = 0
Workaround
Using stmt.setObject(2, null, Types.VARCHAR); instead.
Resolution
The issue has been fixed. The driver now correctly detects the DummyColumn and creates the real column even when using setObject(2, null).
Example
stmt.setObject(2, null); // sets null on DummyColumn -> Works now