Skip to content

Commit e7d5688

Browse files
bjcoombsTomáš Kraus
authored andcommitted
Fix Incorrect SQL Type for null Parameters in JDBC Parameter Binding
This PR addresses an issue in the JDBC parameter binding logic where null values were incorrectly being set with Types.VARCHAR SQL type. This behavior could lead to SQL exceptions when inserting null into non-VARCHAR columns in a database. The proposed change ensures that null values are set with Types.NULL, allowing the JDBC driver to correctly interpret the intended type based on the column definition. Problem Description: When attempting to insert null values into a database using the Helidon JDBC client, the fixed SQL type of Types.VARCHAR for null parameters leads to type mismatch errors for columns of types other than VARCHAR. For example, inserting null into a NUMERIC column results in a PSQLException with a message indicating a type mismatch. Proposed Solution: The fix involves changing the SQL type for null parameters from Types.VARCHAR to Types.NULL in the setParameter method of the JDBC parameter handling logic. This change allows the JDBC driver to determine the correct type for the null value based on the context of the column it is being inserted into, thus preventing type mismatch errors.
1 parent 7d5ec7e commit e7d5688

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatement.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
*/
1616
package io.helidon.dbclient.jdbc;
1717

18+
import io.helidon.dbclient.DbClientException;
19+
import io.helidon.dbclient.DbClientServiceContext;
20+
import io.helidon.dbclient.DbIndexedStatementParameters;
21+
import io.helidon.dbclient.DbNamedStatementParameters;
22+
import io.helidon.dbclient.DbStatement;
23+
import io.helidon.dbclient.DbStatementBase;
24+
import io.helidon.dbclient.DbStatementParameters;
25+
1826
import java.io.ByteArrayInputStream;
1927
import java.io.CharArrayReader;
2028
import java.lang.System.Logger.Level;
@@ -31,14 +39,6 @@
3139
import java.util.Map;
3240
import java.util.UUID;
3341

34-
import io.helidon.dbclient.DbClientException;
35-
import io.helidon.dbclient.DbClientServiceContext;
36-
import io.helidon.dbclient.DbIndexedStatementParameters;
37-
import io.helidon.dbclient.DbNamedStatementParameters;
38-
import io.helidon.dbclient.DbStatement;
39-
import io.helidon.dbclient.DbStatementBase;
40-
import io.helidon.dbclient.DbStatementParameters;
41-
4242
/**
4343
* JDBC statement base implementation.
4444
*
@@ -299,7 +299,7 @@ private void setParameter(PreparedStatement statement, int index, Object paramet
299299
statement.setBoolean(index, b);
300300
} else if (parameter == null) {
301301
// Normally null is passed as a DatabaseField so the type is included, but in some case may be passed directly.
302-
statement.setNull(index, Types.VARCHAR);
302+
statement.setNull(index, Types.NULL);
303303
} else if (parameter instanceof byte[] b) {
304304
if (jdbcContext().parametersConfig().useByteArrayBinding()) {
305305
ByteArrayInputStream inputStream = new ByteArrayInputStream(b);

0 commit comments

Comments
 (0)