Skip to content

Commit

Permalink
Rethrow connection exceptions after MariaDbServerPreparedStatement fa…
Browse files Browse the repository at this point in the history
…ils.

The fix for CONJ-238 was to catch all SQLExceptions thrown by the constructor
for MariaDbServerPreparedStatement, and fallback to a client prepared
statement. This is fine except for SQLNonTransientConnectionExceptions, which
can be the result of an IOException that leaves PacketOutputStream in an
invalid state.

If that happens, then executing the returned MariaDbClientPreparedStatement
will fail with a mysterious "Last stream not finished" (or, as of 1.3.5,
"Stream has already closed") error, with no indication of what previously went
wrong.
  • Loading branch information
ingramj committed Mar 14, 2016
1 parent b3e5557 commit f2a4571
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/mariadb/jdbc/MariaDbConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ public PreparedStatement internalPrepareStatement(final String sql, final int au
if (!options.allowMultiQueries && !options.rewriteBatchedStatements && options.useServerPrepStmts && checkIfPreparable(sql)) {
try {
return new MariaDbServerPreparedStatement(this, sql, autoGeneratedKeys);
} catch (SQLNonTransientConnectionException e) {
throw e;
} catch (SQLException e) {
//on some specific case, server cannot prepared data (CONJ-238)
return new MariaDbClientPreparedStatement(this, sql, autoGeneratedKeys);
Expand Down

0 comments on commit f2a4571

Please sign in to comment.