Package io.github.connellite.jdbc
Class QueryUtils
java.lang.Object
io.github.connellite.jdbc.QueryUtils
Executes parameterized SQL queries via
PreparedStatement.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int[]executeBatch(Connection connection, String sql, Object[][] batchParams) Runs the same prepared statement for many parameter sets (batch).static booleanexecuteCall(Connection connection, String call, Object... inParams) Executes a stored procedure or function call with IN parameters only; returns the same meaning asPreparedStatement.execute().static int[]executeNamedBatch(Connection connection, NamedQuery namedQuery, Map<String, Object> params) BindsparamsontonamedQuery, adds that parameter set as one batch entry, and executes the batch.static int[]executeNamedBatch(Connection connection, String namedQuery, Map<String, Object> params) RunsnamedQueryonce as a JDBC batch withparams.static booleanexecuteNamedCall(Connection connection, NamedQuery namedQuery, Map<String, Object> params) BindsparamsontonamedQueryand executes the call.static booleanexecuteNamedCall(Connection connection, String call, Map<String, Object> params) Executes a named call (:nameparameters) with IN parameters only.static booleanexecuteNamedQuery(Connection connection, NamedQuery namedQuery, Map<String, Object> params) BindsparamsontonamedQueryand executes it.static booleanexecuteNamedQuery(Connection connection, String namedQuery, Map<String, Object> params) Executes a named non-SELECT query.static booleanexecuteQuery(Connection connection, String query, Object... params) Executes a non-SELECT query.static ResultSetselectFromCall(Connection connection, String call, Object... inParams) Executes a call that returns a result set (first non-nullResultSetfromPreparedStatement.execute()/Statement.getMoreResults()), wrapped as a managedResultSetthat closes both resources.static ResultSetselectFromCallCached(Connection connection, String call, Object... inParams) Executes a call that returns a result set (first non-nullResultSetfromPreparedStatement.execute()/Statement.getMoreResults()), detached as aCachedRowSet.static ResultSetselectNamedFromCall(Connection connection, NamedQuery namedQuery, Map<String, Object> params) BindsparamsontonamedQueryand returns the first non-nullResultSetfromPreparedStatement.execute()/Statement.getMoreResults().static ResultSetselectNamedFromCall(Connection connection, String call, Map<String, Object> params) Executes a named call that returns a result set.static ResultSetselectNamedFromCallCached(Connection connection, NamedQuery namedQuery, Map<String, Object> params) BindsparamsontonamedQueryand returns the first non-nullResultSetfromPreparedStatement.execute()/Statement.getMoreResults()as aCachedRowSet.static ResultSetselectNamedFromCallCached(Connection connection, String call, Map<String, Object> params) Executes a named call and returns detached rows as aCachedRowSet.static ResultSetselectNamedQuery(Connection connection, NamedQuery namedQuery, Map<String, Object> params) BindsparamsontonamedQueryand executes it as a SELECT.static ResultSetselectNamedQuery(Connection connection, String namedQuery, Map<String, Object> params) static ResultSetselectNamedQueryCached(Connection connection, NamedQuery namedQuery, Map<String, Object> params) static ResultSetselectNamedQueryCached(Connection connection, String namedQuery, Map<String, Object> params) Executes a named SELECT and returns detached rows as aCachedRowSet.static ResultSetselectQuery(Connection connection, String query, Object... params) static ResultSetselectQueryCached(Connection connection, String query, Object... params) Executes a SELECT query and returns detached rows as aCachedRowSet.
-
Constructor Details
-
QueryUtils
public QueryUtils()
-
-
Method Details
-
selectQuery
public static ResultSet selectQuery(Connection connection, String query, Object... params) throws SQLException - Throws:
SQLException
-
selectQueryCached
public static ResultSet selectQueryCached(Connection connection, String query, Object... params) throws SQLException Executes a SELECT query and returns detached rows as aCachedRowSet. UnlikeselectQuery(Connection, String, Object...), the returned result is independent from the underlying JDBCResultSet/PreparedStatement: both are closed before this method returns. Not recommended for large result sets because all rows are materialized in memory.- Throws:
SQLException
-
executeQuery
public static boolean executeQuery(Connection connection, String query, Object... params) throws SQLException Executes a non-SELECT query.- Throws:
SQLException
-
executeBatch
public static int[] executeBatch(Connection connection, String sql, Object[][] batchParams) throws SQLException Runs the same prepared statement for many parameter sets (batch). Returns update counts per batch entry; order matchesbatchParams.- Throws:
SQLException
-
selectNamedQuery
public static ResultSet selectNamedQuery(Connection connection, String namedQuery, Map<String, Object> params) throws SQLExceptionExecutes a named SELECT (:nameparameters) and returns a result set wrapper that closes bothStatementandResultSet.- Throws:
SQLException
-
selectNamedQuery
public static ResultSet selectNamedQuery(Connection connection, NamedQuery namedQuery, Map<String, Object> params) throws SQLExceptionBindsparamsontonamedQueryand executes it as a SELECT. The returned wrapper closes bothStatementandResultSet.- Throws:
SQLException
-
selectNamedQueryCached
public static ResultSet selectNamedQueryCached(Connection connection, String namedQuery, Map<String, Object> params) throws SQLExceptionExecutes a named SELECT and returns detached rows as aCachedRowSet. The JDBCResultSetandPreparedStatementare closed before this method returns.- Throws:
SQLException
-
selectNamedQueryCached
public static ResultSet selectNamedQueryCached(Connection connection, NamedQuery namedQuery, Map<String, Object> params) throws SQLException- Throws:
SQLException
-
executeNamedQuery
public static boolean executeNamedQuery(Connection connection, String namedQuery, Map<String, Object> params) throws SQLExceptionExecutes a named non-SELECT query. Return value matchesPreparedStatement.execute().- Throws:
SQLException
-
executeNamedQuery
public static boolean executeNamedQuery(Connection connection, NamedQuery namedQuery, Map<String, Object> params) throws SQLException- Throws:
SQLException
-
executeNamedBatch
public static int[] executeNamedBatch(Connection connection, String namedQuery, Map<String, Object> params) throws SQLExceptionRunsnamedQueryonce as a JDBC batch withparams. Returns the single update count fromStatement.executeBatch().- Throws:
SQLException
-
executeNamedBatch
public static int[] executeNamedBatch(Connection connection, NamedQuery namedQuery, Map<String, Object> params) throws SQLExceptionBindsparamsontonamedQuery, adds that parameter set as one batch entry, and executes the batch.- Throws:
SQLException
-
executeCall
public static boolean executeCall(Connection connection, String call, Object... inParams) throws SQLException Executes a stored procedure or function call with IN parameters only; returns the same meaning asPreparedStatement.execute().- Throws:
SQLException
-
selectFromCall
public static ResultSet selectFromCall(Connection connection, String call, Object... inParams) throws SQLException Executes a call that returns a result set (first non-nullResultSetfromPreparedStatement.execute()/Statement.getMoreResults()), wrapped as a managedResultSetthat closes both resources. IN parameters only.- Throws:
SQLException
-
selectFromCallCached
public static ResultSet selectFromCallCached(Connection connection, String call, Object... inParams) throws SQLException Executes a call that returns a result set (first non-nullResultSetfromPreparedStatement.execute()/Statement.getMoreResults()), detached as aCachedRowSet. UnlikeselectFromCall(Connection, String, Object...), the returned data is fully copied, so the original JDBCResultSetandCallableStatementare closed inside this method. Not recommended for large result sets because all rows are materialized in memory. IN parameters only.- Throws:
SQLException
-
executeNamedCall
public static boolean executeNamedCall(Connection connection, String call, Map<String, Object> params) throws SQLExceptionExecutes a named call (:nameparameters) with IN parameters only. Return value matchesPreparedStatement.execute().- Throws:
SQLException
-
executeNamedCall
public static boolean executeNamedCall(Connection connection, NamedQuery namedQuery, Map<String, Object> params) throws SQLExceptionBindsparamsontonamedQueryand executes the call. Return value matchesPreparedStatement.execute(). IN parameters only.- Throws:
SQLException
-
selectNamedFromCall
public static ResultSet selectNamedFromCall(Connection connection, String call, Map<String, Object> params) throws SQLExceptionExecutes a named call that returns a result set. The wrapper closes both the call and theResultSet. IN parameters only.- Throws:
SQLException
-
selectNamedFromCall
public static ResultSet selectNamedFromCall(Connection connection, NamedQuery namedQuery, Map<String, Object> params) throws SQLExceptionBindsparamsontonamedQueryand returns the first non-nullResultSetfromPreparedStatement.execute()/Statement.getMoreResults(). The wrapper closes both the call and theResultSet. IN parameters only.- Throws:
SQLException
-
selectNamedFromCallCached
public static ResultSet selectNamedFromCallCached(Connection connection, String call, Map<String, Object> params) throws SQLExceptionExecutes a named call and returns detached rows as aCachedRowSet. The JDBCResultSetandCallableStatementare closed before this method returns. IN parameters only.- Throws:
SQLException
-
selectNamedFromCallCached
public static ResultSet selectNamedFromCallCached(Connection connection, NamedQuery namedQuery, Map<String, Object> params) throws SQLExceptionBindsparamsontonamedQueryand returns the first non-nullResultSetfromPreparedStatement.execute()/Statement.getMoreResults()as aCachedRowSet. The JDBCResultSetandCallableStatementare closed before this method returns. IN parameters only.- Throws:
SQLException
-