public abstract class JdbcUtils extends Object
Generic utility methods for working with JDBC.
Contains code from Spring's org.springframework.jdbc.support.JdbcUtils.
| Constructor and Description |
|---|
JdbcUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
closeConnection(Connection con)
Close the given JDBC Connection and ignore any thrown exception.
|
static void |
closeResultSet(ResultSet rs)
Close the given JDBC ResultSet and ignore any thrown exception.
|
static void |
closeStatement(Statement stmt)
Close the given JDBC Statement and ignore any thrown exception.
|
static Object |
extractDatabaseMetaData(DataSource dataSource,
DatabaseMetaDataCallback action)
Extract database meta data via the given DatabaseMetaDataCallback.
|
static Object |
extractDatabaseMetaData(DataSource dataSource,
String metaDataMethodName)
Call the specified method on DatabaseMetaData for the given DataSource,
and extract the invocation result.
|
public static void closeConnection(Connection con)
con - the JDBC Connection to close (may be null)public static void closeStatement(Statement stmt)
stmt - the JDBC Statement to close (may be null)public static void closeResultSet(ResultSet rs)
rs - the JDBC ResultSet to close (may be null)public static Object extractDatabaseMetaData(DataSource dataSource, DatabaseMetaDataCallback action) throws MetaDataAccessException
This method will open a connection to the database and retrieve the database metadata. Since this method is called before the exception translation feature is configured for a datasource, this method can not rely on the SQLException translation functionality.
Any exceptions will be wrapped in a MetaDataAccessException. This is a checked exception and any calling code should catch and handle this exception. You can just log the error and hope for the best, but there is probably a more serious error that will reappear when you try to access the database again.
dataSource - the DataSource to extract metadata foraction - callback that will do the actual workprocessMetaData methodMetaDataAccessException - if meta data access failedpublic static Object extractDatabaseMetaData(DataSource dataSource, String metaDataMethodName) throws MetaDataAccessException
dataSource - the DataSource to extract meta data formetaDataMethodName - the name of the DatabaseMetaData method to callMetaDataAccessException - if we couldn't access the DatabaseMetaData
or failed to invoke the specified methodDatabaseMetaData