From c490e81ee0055569b3132a2a0fdf3b135b537aed Mon Sep 17 00:00:00 2001 From: VanniMaceria Date: Mon, 14 Oct 2024 16:55:03 +0200 Subject: [PATCH] Risoluzione Issue #4, #5, #6 --- .../apache/commons/dbutils/QueryRunner.java | 40 ++++++++++--------- .../constants/SQLExceptionCostants.java | 8 ++++ 2 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 src/main/java/org/apache/commons/dbutils/constants/SQLExceptionCostants.java diff --git a/src/main/java/org/apache/commons/dbutils/QueryRunner.java b/src/main/java/org/apache/commons/dbutils/QueryRunner.java index 688cecb2..71ff8587 100644 --- a/src/main/java/org/apache/commons/dbutils/QueryRunner.java +++ b/src/main/java/org/apache/commons/dbutils/QueryRunner.java @@ -28,6 +28,8 @@ import javax.sql.DataSource; +import org.apache.commons.dbutils.constants.SQLExceptionCostants; + /** * Executes SQL queries with pluggable strategies for handling * {@code ResultSet}s. This class is thread safe. @@ -131,15 +133,15 @@ public QueryRunner(final StatementConfiguration stmtConfig) { */ public int[] batch(final Connection conn, final String sql, final Object[][] params) throws SQLException { if (conn == null) { - throw new SQLException("Null connection"); + throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR); } if (sql == null) { - throw new SQLException("Null SQL statement"); + throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR); } if (params == null) { - throw new SQLException("Null parameters. If parameters aren't need, pass an empty array."); + throw new SQLException(SQLExceptionCostants.NULL_PARAMS_ERROR); } PreparedStatement stmt = null; @@ -206,11 +208,11 @@ public int[] batch(final String sql, final Object[][] params) throws SQLExceptio */ public int execute(final Connection conn, final String sql, final Object... params) throws SQLException { if (conn == null) { - throw new SQLException("Null connection"); + throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR); } if (sql == null) { - throw new SQLException("Null SQL statement"); + throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR); } CallableStatement stmt = null; @@ -257,15 +259,15 @@ public int execute(final Connection conn, final String sql, final Object... para */ public List execute(final Connection conn, final String sql, final ResultSetHandler rsh, final Object... params) throws SQLException { if (conn == null) { - throw new SQLException("Null connection"); + throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR); } if (sql == null) { - throw new SQLException("Null SQL statement"); + throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR); } if (rsh == null) { - throw new SQLException("Null ResultSetHandler"); + throw new SQLException(SQLExceptionCostants.NULL_RESULT_SET_ERROR); } CallableStatement stmt = null; @@ -381,15 +383,15 @@ public T insert(final Connection conn, final String sql, final ResultSetHand */ public T insert(final Connection conn, final String sql, final ResultSetHandler rsh, final Object... params) throws SQLException { if (conn == null) { - throw new SQLException("Null connection"); + throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR); } if (sql == null) { - throw new SQLException("Null SQL statement"); + throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR); } if (rsh == null) { - throw new SQLException("Null ResultSetHandler"); + throw new SQLException(SQLExceptionCostants.NULL_RESULT_SET_ERROR); } Statement stmt = null; @@ -469,15 +471,15 @@ public T insert(final String sql, final ResultSetHandler rsh, final Objec */ public T insertBatch(final Connection conn, final String sql, final ResultSetHandler rsh, final Object[][] params) throws SQLException { if (conn == null) { - throw new SQLException("Null connection"); + throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR); } if (sql == null) { - throw new SQLException("Null SQL statement"); + throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR); } if (params == null) { - throw new SQLException("Null parameters. If parameters aren't need, pass an empty array."); + throw new SQLException(SQLExceptionCostants.NULL_PARAMS_ERROR); } PreparedStatement stmt = null; @@ -583,15 +585,15 @@ public T query(final Connection conn, final String sql, final ResultSetHandl */ public T query(final Connection conn, final String sql, final ResultSetHandler rsh, final Object... params) throws SQLException { if (conn == null) { - throw new SQLException("Null connection"); + throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR); } if (sql == null) { - throw new SQLException("Null SQL statement"); + throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR); } if (rsh == null) { - throw new SQLException("Null ResultSetHandler"); + throw new SQLException(SQLExceptionCostants.NULL_RESULT_SET_ERROR); } Statement stmt = null; @@ -759,11 +761,11 @@ public int update(final Connection conn, final String sql, final Object param) t */ public int update(final Connection conn, final String sql, final Object... params) throws SQLException { if (conn == null) { - throw new SQLException("Null connection"); + throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR); } if (sql == null) { - throw new SQLException("Null SQL statement"); + throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR); } Statement stmt = null; diff --git a/src/main/java/org/apache/commons/dbutils/constants/SQLExceptionCostants.java b/src/main/java/org/apache/commons/dbutils/constants/SQLExceptionCostants.java new file mode 100644 index 00000000..b65f1254 --- /dev/null +++ b/src/main/java/org/apache/commons/dbutils/constants/SQLExceptionCostants.java @@ -0,0 +1,8 @@ +package org.apache.commons.dbutils.constants; + +public class SQLExceptionCostants { + public static final String NULL_CONNECTION_ERROR = "Null connection error"; + public static final String NULL_PARAMS_ERROR = "Null parameters error"; + public static final String NULL_STATEMENT_ERROR = "Null SQL statement"; + public static final String NULL_RESULT_SET_ERROR = "Null result set error"; +}