@@ -168,13 +168,11 @@ protected byte[] execute(Connection conn, SampleResult sample) throws SQLExcepti
168168 try (Statement stmt = conn .createStatement ()) {
169169 setQueryTimeout (stmt , getIntegerQueryTimeout ());
170170 configureMaxRows (stmt );
171- ResultSet rs = null ;
172- try {
173- rs = stmt .executeQuery (getQuery ());
171+ try (ResultSet rs = stmt .executeQuery (getQuery ())) {
174172 sample .latencyEnd ();
175173 return getStringFromResultSet (rs ).getBytes (ENCODING );
176174 } finally {
177- close ( rs );
175+ commitTransaction ( conn );
178176 }
179177 }
180178 } else if (CALLABLE .equals (currentQueryType )) {
@@ -186,6 +184,8 @@ protected byte[] execute(Connection conn, SampleResult sample) throws SQLExcepti
186184 sample .latencyEnd ();
187185 String sb = resultSetsToString (cstmt ,hasResultSet , out );
188186 return sb .getBytes (ENCODING );
187+ } finally {
188+ commitTransaction (conn );
189189 }
190190 } else if (UPDATE .equals (currentQueryType )) {
191191 try (Statement stmt = conn .createStatement ()) {
@@ -195,18 +195,18 @@ protected byte[] execute(Connection conn, SampleResult sample) throws SQLExcepti
195195 int updateCount = stmt .getUpdateCount ();
196196 String results = updateCount + " updates" ;
197197 return results .getBytes (ENCODING );
198+ } finally {
199+ commitTransaction (conn );
198200 }
199201 } else if (PREPARED_SELECT .equals (currentQueryType )) {
200202 try (PreparedStatement pstmt = getPreparedStatement (conn )) {
201203 setArguments (pstmt );
202204 configureMaxRows (pstmt );
203- ResultSet rs = null ;
204- try {
205- rs = pstmt .executeQuery ();
205+ try (ResultSet rs = pstmt .executeQuery ()) {
206206 sample .latencyEnd ();
207207 return getStringFromResultSet (rs ).getBytes (ENCODING );
208208 } finally {
209- close ( rs );
209+ commitTransaction ( conn );
210210 }
211211 }
212212 } else if (PREPARED_UPDATE .equals (currentQueryType )) {
@@ -216,6 +216,8 @@ protected byte[] execute(Connection conn, SampleResult sample) throws SQLExcepti
216216 sample .latencyEnd ();
217217 String sb = resultSetsToString (pstmt ,false ,null );
218218 return sb .getBytes (ENCODING );
219+ } finally {
220+ commitTransaction (conn );
219221 }
220222 } else if (ROLLBACK .equals (currentQueryType )){
221223 conn .rollback ();
@@ -238,6 +240,13 @@ protected byte[] execute(Connection conn, SampleResult sample) throws SQLExcepti
238240 }
239241 }
240242
243+ private static void commitTransaction (Connection conn ) throws SQLException {
244+ if (!conn .getAutoCommit ()) {
245+ // HikariCP rollsback the transaction when a dirty connection returns back to the pool, so we commit it explicitly
246+ conn .commit ();
247+ }
248+ }
249+
241250 private void configureMaxRows (Statement stmt ) throws SQLException {
242251 int maxRows = getIntegerResultSetMaxRows ();
243252 if (maxRows >= 0 ) {
0 commit comments