Within `writeData`, an insert statement is being created for every inserted 
row. This is redundant because the insertion statement remains the same between 
inserted rows. (i.e., all columns are included and the values are supplied in 
`insertNewRow`). What is problematic is that the final insert statement is the 
only one being closed. Additionally, if the code throws an exception, then this 
final insert statement does not get closed as well.

This PR
- Ensures the statement is created only once (and closed)
- Ensures that if the code throws an exception, the statement is still closed

Note that the `finally` block follows similar to behavior to that in 
`CachedRowSetReader.readData`, where the exception that could occur in the 
`close` is discarded, if the original code already threw an exception. I did 
not find it necessary here to retain the closed exception via `addSuppressed` 
if the original code also threw.

---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK 
Interim AI Policy](https://openjdk.org/legal/ai).

-------------

Commit messages:
 - init

Changes: https://git.openjdk.org/jdk/pull/33639/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=33639&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8395714
  Stats: 104 lines in 1 file changed: 37 ins; 24 del; 43 mod
  Patch: https://git.openjdk.org/jdk/pull/33639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/33639/head:pull/33639

PR: https://git.openjdk.org/jdk/pull/33639

Reply via email to