public class JdbcUtils extends Object
| Modifier and Type | Class and Description | 
|---|---|
| static interface  | JdbcUtils.SqlFunctionDescribes a function that creates a new  PreparedStatementready to be executed. | 
| static interface  | JdbcUtils.SqlResultConverter<R>Describes a function that converts a  ResultSetinto a result of typeR. | 
| Modifier and Type | Method and Description | 
|---|---|
| static void | closeQuietly(Connection connection)Close the given  connection, if possible. | 
| static void | closeQuietly(ResultSet resultSet)Close the given  resultSet, if possible. | 
| static void | closeQuietly(Statement statement)Close the given  statement, if possible. | 
| static int[] | executeBatch(Connection connection,
            JdbcUtils.SqlFunction sqlFunction,
            Consumer<SQLException> errorHandler)Execute the a batch update or insert statement produced by the given  sqlFunction. | 
| static <R> R | executeQuery(Connection connection,
            JdbcUtils.SqlFunction sqlFunction,
            JdbcUtils.SqlResultConverter<R> sqlResultConverter,
            Function<SQLException,RuntimeException> errorHandler)Execute the query given by the  sqlFunction. | 
| static int[] | executeUpdates(Connection connection,
              Consumer<SQLException> errorHandler,
              JdbcUtils.SqlFunction... sqlFunctions)Execute the update statements produced by the given  sqlFunctions. | 
| static <R> JdbcUtils.SqlResultConverter<List<R>> | listResults(JdbcUtils.SqlResultConverter<R> singleResultConverter)Create a converter that produces a List of results of type  Rfrom a converter that produces a single
 result. | 
public static <R> R executeQuery(Connection connection, JdbcUtils.SqlFunction sqlFunction, JdbcUtils.SqlResultConverter<R> sqlResultConverter, Function<SQLException,RuntimeException> errorHandler)
sqlFunction. The ResultSet returned when the query is executed
 will be converted using the given sqlResultConverter. Any errors will be handled by the given errorHandler.R - the result of the query after conversionconnection - connection to the underlying database that should be used for the querysqlFunction - the function that returns a PreparedStatement to execute the query againstsqlResultConverter - converts the result set to a value of type RerrorHandler - handles errors as result of executing the query or converting the result setpublic static int[] executeUpdates(Connection connection, Consumer<SQLException> errorHandler, JdbcUtils.SqlFunction... sqlFunctions)
sqlFunctions. Any errors will be handled by the given
 errorHandler.connection - connection to the underlying database that should be used for the updateerrorHandler - handles errors as result of executing the updatesqlFunctions - the functions that produce the update statementspublic static int[] executeBatch(Connection connection, JdbcUtils.SqlFunction sqlFunction, Consumer<SQLException> errorHandler)
sqlFunction. Any errors will be
 handled by the given errorHandler.connection - connection to the underlying database that should be used for the updatesqlFunction - the function that produces the batch update statementerrorHandler - handles errors as result of executing the updatepublic static <R> JdbcUtils.SqlResultConverter<List<R>> listResults(JdbcUtils.SqlResultConverter<R> singleResultConverter)
R from a converter that produces a single
 result. The returned converter iterates over the resultSet until all results have been converted and added to
 the list.R - the type of result produced by the singleResultConvertersingleResultConverter - the converter that can convert a single result from the current position of the
                              resultSetpublic static void closeQuietly(ResultSet resultSet)
resultSet, if possible. All exceptions are discarded.resultSet - The resource to close. May be null.public static void closeQuietly(Statement statement)
statement, if possible. All exceptions are discarded.statement - The resource to close. May be null.public static void closeQuietly(Connection connection)
connection, if possible. All exceptions are discarded.connection - The resource to close. May be null.Copyright © 2010–2017. All rights reserved.