Skip to content

Commit c490e81

Browse files
committed
Risoluzione Issue apache#4, apache#5, apache#6
1 parent 1121337 commit c490e81

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

src/main/java/org/apache/commons/dbutils/QueryRunner.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
import javax.sql.DataSource;
3030

31+
import org.apache.commons.dbutils.constants.SQLExceptionCostants;
32+
3133
/**
3234
* Executes SQL queries with pluggable strategies for handling
3335
* {@code ResultSet}s. This class is thread safe.
@@ -131,15 +133,15 @@ public QueryRunner(final StatementConfiguration stmtConfig) {
131133
*/
132134
public int[] batch(final Connection conn, final String sql, final Object[][] params) throws SQLException {
133135
if (conn == null) {
134-
throw new SQLException("Null connection");
136+
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
135137
}
136138

137139
if (sql == null) {
138-
throw new SQLException("Null SQL statement");
140+
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
139141
}
140142

141143
if (params == null) {
142-
throw new SQLException("Null parameters. If parameters aren't need, pass an empty array.");
144+
throw new SQLException(SQLExceptionCostants.NULL_PARAMS_ERROR);
143145
}
144146

145147
PreparedStatement stmt = null;
@@ -206,11 +208,11 @@ public int[] batch(final String sql, final Object[][] params) throws SQLExceptio
206208
*/
207209
public int execute(final Connection conn, final String sql, final Object... params) throws SQLException {
208210
if (conn == null) {
209-
throw new SQLException("Null connection");
211+
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
210212
}
211213

212214
if (sql == null) {
213-
throw new SQLException("Null SQL statement");
215+
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
214216
}
215217

216218
CallableStatement stmt = null;
@@ -257,15 +259,15 @@ public int execute(final Connection conn, final String sql, final Object... para
257259
*/
258260
public <T> List<T> execute(final Connection conn, final String sql, final ResultSetHandler<T> rsh, final Object... params) throws SQLException {
259261
if (conn == null) {
260-
throw new SQLException("Null connection");
262+
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
261263
}
262264

263265
if (sql == null) {
264-
throw new SQLException("Null SQL statement");
266+
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
265267
}
266268

267269
if (rsh == null) {
268-
throw new SQLException("Null ResultSetHandler");
270+
throw new SQLException(SQLExceptionCostants.NULL_RESULT_SET_ERROR);
269271
}
270272

271273
CallableStatement stmt = null;
@@ -381,15 +383,15 @@ public <T> T insert(final Connection conn, final String sql, final ResultSetHand
381383
*/
382384
public <T> T insert(final Connection conn, final String sql, final ResultSetHandler<T> rsh, final Object... params) throws SQLException {
383385
if (conn == null) {
384-
throw new SQLException("Null connection");
386+
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
385387
}
386388

387389
if (sql == null) {
388-
throw new SQLException("Null SQL statement");
390+
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
389391
}
390392

391393
if (rsh == null) {
392-
throw new SQLException("Null ResultSetHandler");
394+
throw new SQLException(SQLExceptionCostants.NULL_RESULT_SET_ERROR);
393395
}
394396

395397
Statement stmt = null;
@@ -469,15 +471,15 @@ public <T> T insert(final String sql, final ResultSetHandler<T> rsh, final Objec
469471
*/
470472
public <T> T insertBatch(final Connection conn, final String sql, final ResultSetHandler<T> rsh, final Object[][] params) throws SQLException {
471473
if (conn == null) {
472-
throw new SQLException("Null connection");
474+
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
473475
}
474476

475477
if (sql == null) {
476-
throw new SQLException("Null SQL statement");
478+
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
477479
}
478480

479481
if (params == null) {
480-
throw new SQLException("Null parameters. If parameters aren't need, pass an empty array.");
482+
throw new SQLException(SQLExceptionCostants.NULL_PARAMS_ERROR);
481483
}
482484

483485
PreparedStatement stmt = null;
@@ -583,15 +585,15 @@ public <T> T query(final Connection conn, final String sql, final ResultSetHandl
583585
*/
584586
public <T> T query(final Connection conn, final String sql, final ResultSetHandler<T> rsh, final Object... params) throws SQLException {
585587
if (conn == null) {
586-
throw new SQLException("Null connection");
588+
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
587589
}
588590

589591
if (sql == null) {
590-
throw new SQLException("Null SQL statement");
592+
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
591593
}
592594

593595
if (rsh == null) {
594-
throw new SQLException("Null ResultSetHandler");
596+
throw new SQLException(SQLExceptionCostants.NULL_RESULT_SET_ERROR);
595597
}
596598

597599
Statement stmt = null;
@@ -759,11 +761,11 @@ public int update(final Connection conn, final String sql, final Object param) t
759761
*/
760762
public int update(final Connection conn, final String sql, final Object... params) throws SQLException {
761763
if (conn == null) {
762-
throw new SQLException("Null connection");
764+
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
763765
}
764766

765767
if (sql == null) {
766-
throw new SQLException("Null SQL statement");
768+
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
767769
}
768770

769771
Statement stmt = null;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.apache.commons.dbutils.constants;
2+
3+
public class SQLExceptionCostants {
4+
public static final String NULL_CONNECTION_ERROR = "Null connection error";
5+
public static final String NULL_PARAMS_ERROR = "Null parameters error";
6+
public static final String NULL_STATEMENT_ERROR = "Null SQL statement";
7+
public static final String NULL_RESULT_SET_ERROR = "Null result set error";
8+
}

0 commit comments

Comments
 (0)