Skip to content

Commit 97ff164

Browse files
author
Paultagoras
committed
Update StatementImpl.java
1 parent fe585c8 commit 97ff164

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.sql.SQLWarning;
1818
import java.sql.Statement;
1919
import java.util.ArrayList;
20+
import java.util.Arrays;
2021
import java.util.Collections;
2122
import java.util.List;
2223
import java.util.concurrent.TimeUnit;
@@ -161,12 +162,11 @@ public int executeUpdate(String sql, QuerySettings settings) throws SQLException
161162
lastSql = parseJdbcEscapeSyntax(sql);
162163
try (QueryResponse response = queryTimeout == 0 ? connection.client.query(lastSql, mergedSettings).get()
163164
: connection.client.query(lastSql, mergedSettings).get(queryTimeout, TimeUnit.SECONDS)) {
164-
165165
currentResultSet = null;
166166
metrics = response.getMetrics();
167167
lastQueryId = response.getQueryId();
168168
} catch (Exception e) {
169-
throw new RuntimeException(e);
169+
throw ExceptionUtils.toSqlState(e);
170170
}
171171

172172
return (int) metrics.getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong();
@@ -302,8 +302,10 @@ public ResultSet getResultSet() throws SQLException {
302302
@Override
303303
public int getUpdateCount() throws SQLException {
304304
checkClosed();
305-
if (currentResultSet == null) {
306-
return (int) metrics.getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong();
305+
if (currentResultSet == null && metrics != null) {
306+
int updateCount = (int) metrics.getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong();
307+
metrics = null;// clear metrics
308+
return updateCount;
307309
}
308310

309311
return -1;

0 commit comments

Comments
 (0)