JDBC driver 12.10 has a regression/bug for concatenated SQLStatement.

HAIBING Qiao 0 Reputation points
2025-07-16T22:25:29.3333333+00:00

Starting JDBC driver 12.10, the following resultset will be null and seems ignore the select statement at the end. This is a regression from previous JDBC driver versions. It broke our software that has been deployed to many of our customers and prevent them from upgrading to JDBC driver 12.10. Thanks!

	PreparedStatement ps= conn.prepareStatement("delete from TestTable; INSERT INTO TestTable (c1,c2) VALUES (?, ?); select * from TestTable "); 

           ResultSet resultset = ps.execute();
SQL Server | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 128.9K Reputation points MVP Volunteer Moderator
    2025-07-17T07:57:00.3266667+00:00

    The place to report a bug is https://feedback.azure.com/d365community/forum/04fe6ee0-3b25-ec11-b6e6-000d3a4f0da0. However, this is only to let Microsoft know about the issue. They will address the issue as they see fit. If this is a blocking issue and you need a fix, you need to open a support case.

    I don't work with Java and JDBC myself, so I cannot run any tests myself. However, I suspect that if you issue SET NOCOUNT ON on the connection before you run the above, you will get the result set. This type of problems have been seen with other client APIs, and SET NOCOUNT ON has been the solution.

    0 comments No comments

  2. Dinesh Yadlapalli 0 Reputation points Microsoft External Staff Moderator
    2025-11-27T07:22:35.41+00:00

    Hi @HAIBING Qiao ,

    Thank you for reaching out to the Microsoft Q & A Forum.

    JDBC drivers enforce stricter rules for PreparedStatement execution. They often disallow multiple SQL statements in one call for security and consistency reasons. In older versions, the driver parsed and executed all statements sequentially, returning the last ResultSet. In 12.10, the driver likely ignores subsequent statements after the first DML operation or treats them as invalid for PreparedStatement.

    ps.execute() now returns false indicating no ResultSet because the first statement (DELETE) does not produce a result set. The SELECT at the end is never executed, so resultset becomes null.

    Please try below workarounds.

    1. Split the statements into separate calls.

    PreparedStatement deleteStmt = conn.prepareStatement("DELETE FROM TestTable");

    deleteStmt.executeUpdate();

    PreparedStatement insertStmt = conn.prepareStatement("INSERT INTO TestTable (c1,c2) VALUES (?, ?)");

    insertStmt.setString(1, value1);

    insertStmt.setString(2, value2);

    insertStmt.executeUpdate();

    PreparedStatement selectStmt = conn.prepareStatement("SELECT * FROM TestTable");

    ResultSet rs = selectStmt.executeQuery();

    1. Use Statement with execute() for multiple statements.

    Statement stmt = conn.createStatement();

    boolean hasResultSet = stmt.execute("DELETE FROM TestTable; INSERT INTO TestTable (c1,c2) VALUES ('a','b'); SELECT * FROM TestTable");

    while (true) {

    if (hasResultSet) {

    ResultSet rs = stmt.getResultSet();

    } else {

    int updateCount = stmt.getUpdateCount();

    if (updateCount == -1) break;

    }    
    

    hasResultSet = stmt.getMoreResults();

    }

    1. Batch updates for DML, then a separate query for SELECT.

    I hope this information helps. Please do let us know if you have any further queries.

     

    Regards,

    Dinesh


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.