-
Notifications
You must be signed in to change notification settings - Fork 613
[jdbc-v2] Disabled calling some Statement method from PreparedStatement. #2328
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR disables calling certain Statement methods on PreparedStatement objects to prevent accidental misuse and internal state corruption. Key changes include:
- Adding tests to verify that forbidden Statement methods throw SQLException.
- Introducing new SQL state codes and updating exception messages.
- Refactoring method names and access modifiers for consistency in StatementImpl and PreparedStatementImpl.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java | Added tests to check that disallowed Statement methods throw exceptions. |
| jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/ExceptionUtils.java | Updated error codes along with inline comments for better clarity. |
| jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java | Refactored method names to their "Impl" variants and updated enum visibility. |
| jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java | Overridden forbidden Statement methods to throw clear SQLException messages. |
| public static final String SQL_STATE_INVALID_SCHEMA = "3F000"; | ||
| public static final String SQL_STATE_INVALID_TX_STATE = "25000"; | ||
| public static final String SQL_STATE_DATA_EXCEPTION = "22000"; | ||
| // Used only when feature is no supported |
Copilot
AI
Apr 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the grammatical error in the comment: change 'no supported' to 'not supported'.
| // Used only when feature is no supported | |
| // Used only when feature is not supported |
|




Summary
According to JDBC there are some method from
Statementinterface that cannot be called on instance ofPreparedStatement. It is done to protect internal state. Imaging having aPrepredStatement("SELECT * FROM t WHERE v > ?")and executingexecuteQuery("SELECT * FROM t1"). In this case internal result set will be pointing to a result of second query not a prepared one.Sometimes it is convenient to create only one object of
PreparedStatementand execute someSETstatements. But it leads to errors and confusing internal state as it is described.Closes: #2339
Checklist
Delete items not relevant to your PR: