|
17 | 17 | import java.sql.SQLWarning; |
18 | 18 | import java.sql.Statement; |
19 | 19 | import java.util.ArrayList; |
| 20 | +import java.util.Arrays; |
20 | 21 | import java.util.Collections; |
21 | 22 | import java.util.List; |
22 | 23 | import java.util.concurrent.TimeUnit; |
@@ -161,12 +162,11 @@ public int executeUpdate(String sql, QuerySettings settings) throws SQLException |
161 | 162 | lastSql = parseJdbcEscapeSyntax(sql); |
162 | 163 | try (QueryResponse response = queryTimeout == 0 ? connection.client.query(lastSql, mergedSettings).get() |
163 | 164 | : connection.client.query(lastSql, mergedSettings).get(queryTimeout, TimeUnit.SECONDS)) { |
164 | | - |
165 | 165 | currentResultSet = null; |
166 | 166 | metrics = response.getMetrics(); |
167 | 167 | lastQueryId = response.getQueryId(); |
168 | 168 | } catch (Exception e) { |
169 | | - throw new RuntimeException(e); |
| 169 | + throw ExceptionUtils.toSqlState(e); |
170 | 170 | } |
171 | 171 |
|
172 | 172 | return (int) metrics.getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong(); |
@@ -302,8 +302,10 @@ public ResultSet getResultSet() throws SQLException { |
302 | 302 | @Override |
303 | 303 | public int getUpdateCount() throws SQLException { |
304 | 304 | 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; |
307 | 309 | } |
308 | 310 |
|
309 | 311 | return -1; |
|
0 commit comments