/** * Default implementation for query execution using a prepared statement. * Subclasses may override this method. */ protected int execute(ExecuteContext ctx, ExecuteListener listener) throws SQLException { int result = 0; PreparedStatement stmt = ctx.statement(); try { listener.executeStart(ctx); // [#1829] Statement.execute() is preferred over Statement.executeUpdate(), as // we might be executing plain SQL and returning results. if (!stmt.execute()) { result = stmt.getUpdateCount(); ctx.rows(result); } listener.executeEnd(ctx); return result; } // [#3011] [#3054] [#6390] [#6413] Consume additional exceptions if there are any catch (SQLException e) { consumeExceptions(ctx.configuration(), stmt, e); if (ctx.settings().getThrowExceptions() != THROW_NONE) throw e; else return stmt.getUpdateCount(); } }
/** * [#5666] Handle the complexity of each dialect's understanding of * correctly calling {@link Statement#execute()}. */ static final SQLException executeStatementAndGetFirstResultSet(ExecuteContext ctx, int skipUpdateCounts) throws SQLException { PreparedStatement stmt = ctx.statement(); try { if (stmt.execute()) { ctx.resultSet(stmt.getResultSet()); } else { ctx.resultSet(null); ctx.rows(stmt.getUpdateCount()); } return null; } // [#3011] [#3054] [#6390] [#6413] Consume additional exceptions if there are any catch (SQLException e) { if (ctx.settings().getThrowExceptions() != THROW_NONE) { consumeExceptions(ctx.configuration(), ctx.statement(), e); throw e; } else { return e; } } }
consumeExceptions(ctx.configuration(), ctx.statement(), e); throw e;