Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return null when applicable from getGeneratedKeys #2180

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

elpete
Copy link

@elpete elpete commented Feb 28, 2024

Currently, there is no way to check if getGeneratedKeys returned null. Instead, when trying to call ResultSet.next() a NullPointerException is thrown.

This method should return an empty ResultSet when there are no generated keys, but not all JDBC drivers do (like Apache Derby) In these cases, I think the safest option is to return null, which can then be checked (and is checked in popular JDBC libraries like JOOQ.)

Currently, there is no way to check if `getGeneratedKeys` returned `null`.  Instead, when trying to call `ResultSet.next()` a `NullPointerException` is thrown.

This method [should return an empty `ResultSet` when there are no generated keys]( https://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html#getGeneratedKeys--), but not all JDBC drivers do (like [Apache](https://github.com/apache/derby/blob/4253dcf4aa37dc64cf7235d494cd2f00f72e678a/java/org.apache.derby.client/org/apache/derby/client/am/ClientStatement.java#L271) [Derby](https://github.com/apache/derby/blob/4253dcf4aa37dc64cf7235d494cd2f00f72e678a/java/org.apache.derby.client/org/apache/derby/client/am/ClientStatement.java#L1378-L1394))  In these cases, I think the safest option is to return `null`, which can then be checked (and is checked in popular JDBC libraries [like JOOQ.](https://github.com/jOOQ/jOOQ/blob/181d838797d8238edd52576df6b7d3827cceb797/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java#L1350-L1352))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant