@@ -71,6 +71,7 @@ class QueryHandler implements QueryOp<QueryHandler> {
71
71
private Integer batchSize
72
72
private long batchDelayMillis = 100
73
73
private int queryCount
74
+ private boolean executeUpdate = false
74
75
75
76
@Override
76
77
QueryOp withStatement (String stm ) {
@@ -97,6 +98,8 @@ class QueryHandler implements QueryOp<QueryHandler> {
97
98
this . batchSize = opts. batchSize as Integer
98
99
if ( opts. batchDelay )
99
100
this . batchDelayMillis = opts. batchDelay as long
101
+ if ( opts. executeUpdate )
102
+ this . executeUpdate = opts. executeUpdate as boolean
100
103
return this
101
104
}
102
105
@@ -156,10 +159,29 @@ class QueryHandler implements QueryOp<QueryHandler> {
156
159
protected void query0 (Connection conn ) {
157
160
try {
158
161
try (Statement stm = conn. createStatement()) {
159
- try ( def rs = stm. executeQuery(normalize(statement)) ) {
160
- if ( emitColumns )
161
- emitColumns(rs)
162
- emitRowsAndClose(rs)
162
+ final String normalizedStmt = normalize(statement)
163
+ // Check if statement is a DDL or UPDATE statement that doesn't return a ResultSet
164
+ boolean isUpdateOrDdl = executeUpdate ||
165
+ normalizedStmt. toUpperCase(). startsWith(" CREATE " ) ||
166
+ normalizedStmt. toUpperCase(). startsWith(" ALTER " ) ||
167
+ normalizedStmt. toUpperCase(). startsWith(" DROP " ) ||
168
+ normalizedStmt. toUpperCase(). startsWith(" INSERT " ) ||
169
+ normalizedStmt. toUpperCase(). startsWith(" UPDATE " ) ||
170
+ normalizedStmt. toUpperCase(). startsWith(" DELETE " );
171
+
172
+ if (isUpdateOrDdl) {
173
+ // Use executeUpdate for statements that don't return ResultSets
174
+ stm. executeUpdate(normalizedStmt)
175
+ // Since there's no ResultSet to emit, just close the channel
176
+ target. bind(Channel . STOP )
177
+ }
178
+ else {
179
+ // For SELECT and other queries that return ResultSets
180
+ try (def rs = stm. executeQuery(normalizedStmt)) {
181
+ if (emitColumns)
182
+ emitColumns(rs)
183
+ emitRowsAndClose(rs)
184
+ }
163
185
}
164
186
}
165
187
}
0 commit comments