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

(Statement/PreparedStatement).executeUpdate() for statements that do not return anything (DDL, ClientSideStatements) throwing exception #1150

Closed
rajatbhatta opened this issue Mar 7, 2023 · 0 comments · Fixed by #1694
Assignees
Labels
api: spanner Issues related to the googleapis/java-spanner-jdbc API.

Comments

@rajatbhatta
Copy link
Contributor

rajatbhatta commented Mar 7, 2023

PreparedStatement.executeUpdate() currently does not work for DDL statements, and throws an exception. It should execute it successfully and return 0 as the result. (Ref)

String DDL = "CREATE TABLE FOO (ID INT64 NOT NULL, NAME STRING(100)) PRIMARY KEY (ID)";
try (PreparedStatement pstmt = connection.prepareStatement(DDL)) {
    int updateCount = pstmt.executeUpdate();
    assertEquals(updateCount, 0);
}

The above fails with the exception com.google.cloud.spanner.jdbc.JdbcSqlExceptionFactory$JdbcSqlExceptionImpl: INVALID_ARGUMENT: Statement is not an update statement: CREATE TABLE FOO (ID INT64 NOT NULL, NAME STRING(100)) PRIMARY KEY (ID).

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner-jdbc API. label Mar 7, 2023
@rajatbhatta rajatbhatta changed the title PreparedStatement.executeUpdate() for DDL statements throwing exception PreparedStatement.executeUpdate() for DDL statements (or statements that return nothing) throwing exception Mar 9, 2023
@rajatbhatta rajatbhatta changed the title PreparedStatement.executeUpdate() for DDL statements (or statements that return nothing) throwing exception (Statement/PreparedStatement).executeUpdate() for statements that do not return anything (DDL, ClientSideStatements) throwing exception Mar 9, 2023
@rajatbhatta rajatbhatta assigned olavloite and unassigned rajatbhatta Aug 25, 2023
olavloite added a commit that referenced this issue Jul 29, 2024
The JDBC driver should now support executing DDL using the
executeUpdate methods of java.sql.Statement and
java.sql.PreparedStatement.

Closes #1150
olavloite added a commit that referenced this issue Aug 6, 2024
The JDBC driver should now support executing DDL using the
executeUpdate methods of java.sql.Statement and
java.sql.PreparedStatement.

Closes #1150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner-jdbc API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants