We have a Spring application connecting to Oracle via SpringJDBC (jdbcTemplate),
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
<version>23.3.0.23.09</version>
</dependency>
In our DAO class we have an INSERT executed with jdbcTemplate.update():
String sql = """
INSERT INTO
MY_TABLE (
COL1,
COL2,
COL3)
VALUES (?, ?, ?)
""";
jdbcTemplate.update(sql, param1, param2, param3/* may be NULL*/);
The 3rd param may be a NULL value getting inserted. When it's not NULL, performance is fast, no issues. But when it happens to be NULL, it takes ~2 min on the first such insert, and it's still pretty slow (about 10-30 sec.) on all subsequent such Inserts.
This is not a DB problem: I verified in the DB (SqlDeveloper) that all INSERTs both with and without NULLs in this column are equally fast directly in the DB, so we can rule out the DB.
Since Oracle treats empty strings as NULLs, we found a good solution: just pass in an empty string for a NULL:
(param3 == null ? "" : param3)
and this fixes the performance issue, and NULL gets inserted. But is this NULL issue a known problem with Oracle's JDBC driver? I don't know if this will always work, like if the NULL/empty equivalence can be turned off in the DB. Are there other workarounds?
VALUES (?, ?, CAST(? AS VARCHAR2)PreparedStatementinstead of going through Spring. If it performs better that way, then your issue is Spring, not the Oracle driver.