@@ -249,33 +249,36 @@ protected void attemptFlush() throws SQLException {
249
249
/** Executes prepared statement and closes all resources of this instance. */
250
250
@ Override
251
251
public synchronized void close () {
252
- if (!closed ) {
253
- closed = true ;
252
+ try {
253
+ if (!closed ) {
254
+ closed = true ;
254
255
255
- if (this .scheduledFuture != null ) {
256
- scheduledFuture .cancel (false );
257
- this .scheduler .shutdown ();
258
- }
256
+ if (this .scheduledFuture != null ) {
257
+ scheduledFuture .cancel (false );
258
+ this .scheduler .shutdown ();
259
+ }
259
260
260
- if (batchCount > 0 ) {
261
- try {
262
- flush ();
263
- } catch (Exception e ) {
264
- LOG .warn ("Writing records to JDBC failed." , e );
265
- throw new RuntimeException ("Writing records to JDBC failed." , e );
261
+ if (batchCount > 0 ) {
262
+ try {
263
+ flush ();
264
+ } catch (Exception e ) {
265
+ LOG .warn ("Writing records to JDBC failed." , e );
266
+ throw new RuntimeException ("Writing records to JDBC failed." , e );
267
+ }
266
268
}
267
- }
268
269
269
- try {
270
- if (jdbcStatementExecutor != null ) {
271
- jdbcStatementExecutor .closeStatements ();
270
+ try {
271
+ if (jdbcStatementExecutor != null ) {
272
+ jdbcStatementExecutor .closeStatements ();
273
+ }
274
+ } catch (SQLException e ) {
275
+ LOG .warn ("Close JDBC writer failed." , e );
272
276
}
273
- } catch (SQLException e ) {
274
- LOG .warn ("Close JDBC writer failed." , e );
275
277
}
278
+ } finally {
279
+ connectionProvider .closeConnection ();
280
+ checkFlushException ();
276
281
}
277
- connectionProvider .closeConnection ();
278
- checkFlushException ();
279
282
}
280
283
281
284
public static Builder builder () {
0 commit comments