@@ -150,11 +150,10 @@ public SqlParamBuilder(Connection dbConnection) {
150
150
}
151
151
152
152
/** Close statement (if any) and set a new SQL template */
153
- public SqlParamBuilder sql (String ... sqlTemplates ) {
153
+ public SqlParamBuilder sql (String ... sqlLines ) {
154
154
close ();
155
155
this .params .clear ();
156
- this .sqlTemplate = sqlTemplates .length == 1
157
- ? sqlTemplates [0 ] : String .join ("\n " , sqlTemplates );
156
+ this .sqlTemplate = sqlLines .length == 1 ? sqlLines [0 ] : String .join ("\n " , sqlLines );
158
157
return this ;
159
158
}
160
159
@@ -164,6 +163,10 @@ public SqlParamBuilder bind(String key, Object... value) {
164
163
return this ;
165
164
}
166
165
166
+ public int execute () throws IllegalStateException , SQLException {
167
+ return prepareStatement ().executeUpdate ();
168
+ }
169
+
167
170
private ResultSet executeSelect () throws IllegalStateException {
168
171
try (AutoCloseable rs = resultSet ) {
169
172
} catch (Exception e ) {
@@ -177,7 +180,7 @@ private ResultSet executeSelect() throws IllegalStateException {
177
180
}
178
181
}
179
182
180
- /** Use a {@link #streamMap(SqlFunction)} rather */
183
+ /** Use the {@link #streamMap(SqlFunction)} or {@link #forEach(SqlConsumer)} methods rather */
181
184
private Stream <ResultSet > stream () {
182
185
final var resultSet = executeSelect ();
183
186
final var iterator = new Iterator <ResultSet >() {
@@ -206,10 +209,6 @@ public <R> Stream<R> streamMap(SqlFunction<ResultSet, ? extends R> mapper ) {
206
209
return stream ().map (mapper );
207
210
}
208
211
209
- public int execute () throws IllegalStateException , SQLException {
210
- return prepareStatement ().executeUpdate ();
211
- }
212
-
213
212
public Connection getConnection () {
214
213
return dbConnection ;
215
214
}
@@ -227,7 +226,7 @@ public void close() {
227
226
}
228
227
229
228
public PreparedStatement prepareStatement () throws SQLException {
230
- final var sqlValues = new ArrayList <>();
229
+ final var sqlValues = new ArrayList <>(params . size () );
231
230
final var sql = buildSql (sqlValues , false );
232
231
final var result = preparedStatement != null
233
232
? preparedStatement
0 commit comments