1
1
/**
2
- * Copyright 2009-2015 the original author or authors.
2
+ * Copyright 2009-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
23
23
import java .sql .ResultSet ;
24
24
import java .sql .ResultSetMetaData ;
25
25
import java .sql .SQLException ;
26
+ import java .sql .SQLWarning ;
26
27
import java .sql .Statement ;
27
28
28
29
/**
@@ -37,6 +38,7 @@ public class ScriptRunner {
37
38
private Connection connection ;
38
39
39
40
private boolean stopOnError ;
41
+ private boolean throwWarning ;
40
42
private boolean autoCommit ;
41
43
private boolean sendFullScript ;
42
44
private boolean removeCRs ;
@@ -56,6 +58,10 @@ public void setStopOnError(boolean stopOnError) {
56
58
this .stopOnError = stopOnError ;
57
59
}
58
60
61
+ public void setThrowWarning (boolean throwWarning ) {
62
+ this .throwWarning = throwWarning ;
63
+ }
64
+
59
65
public void setAutoCommit (boolean autoCommit ) {
60
66
this .autoCommit = autoCommit ;
61
67
}
@@ -227,6 +233,12 @@ private void executeStatement(String command) throws SQLException {
227
233
}
228
234
if (stopOnError ) {
229
235
hasResults = statement .execute (sql );
236
+ if (throwWarning ) {
237
+ SQLWarning warning = statement .getWarnings ();
238
+ if (warning != null ) {
239
+ throw warning ;
240
+ }
241
+ }
230
242
} else {
231
243
try {
232
244
hasResults = statement .execute (sql );
0 commit comments