From 133d410e50ee5d2e113b7739d66f8a47ee8cbe42 Mon Sep 17 00:00:00 2001 From: lihongliustc <778332143@qq.com> Date: Mon, 27 Jun 2016 22:35:04 +0800 Subject: [PATCH] change the way of JDBC commit change the way of JDBC commit --- .../sql/execution/datasources/jdbc/JdbcUtils.scala | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala index 065c8572b06a2..01e2c2ca36dd6 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala @@ -211,18 +211,22 @@ object JdbcUtils extends Logging { rowCount += 1 if (rowCount % batchSize == 0) { stmt.executeBatch() + if (supportsTransactions) { + conn.commit() + } rowCount = 0 } } if (rowCount > 0) { stmt.executeBatch() + if (supportsTransactions) { + conn.commit() + } } } finally { stmt.close() } - if (supportsTransactions) { - conn.commit() - } + committed = true } finally { if (!committed) {