| java.lang.Object org.springframework.jdbc.support.JdbcUtils
JdbcUtils | abstract public class JdbcUtils (Code) | | Generic utility methods for working with JDBC. Mainly for internal use
within the framework, but also useful for custom JDBC access code.
author: Thomas Risberg author: Juergen Hoeller |
Field Summary | |
final public static int | TYPE_UNKNOWN Constant that indicates an unknown (or unspecified) SQL type. |
Method Summary | |
public static void | closeConnection(Connection con) Close the given JDBC Connection and ignore any thrown exception. | public static void | closeResultSet(ResultSet rs) Close the given JDBC ResultSet and ignore any thrown exception. | public static void | closeStatement(Statement stmt) Close the given JDBC Statement and ignore any thrown exception. | public static Object | extractDatabaseMetaData(DataSource dataSource, DatabaseMetaDataCallback action) Extract database meta data via the given DatabaseMetaDataCallback.
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. | public static Object | extractDatabaseMetaData(DataSource dataSource, String metaDataMethodName) Call the specified method on DatabaseMetaData for the given DataSource,
and extract the invocation result. | public static Object | getResultSetValue(ResultSet rs, int index) Retrieve a JDBC column value from a ResultSet, using the most appropriate
value type. | public static boolean | isNumeric(int sqlType) Check whether the given SQL type is numeric. | public static boolean | supportsBatchUpdates(Connection con) Return whether the given JDBC driver supports JDBC 2.0 batch updates. |
TYPE_UNKNOWN | final public static int TYPE_UNKNOWN(Code) | | Constant that indicates an unknown (or unspecified) SQL type.
See Also: java.sql.Types |
closeConnection | public static void closeConnection(Connection con)(Code) | | Close the given JDBC Connection and ignore any thrown exception.
This is useful for typical finally blocks in manual JDBC code.
Parameters: con - the JDBC Connection to close (may be null ) |
closeResultSet | public static void closeResultSet(ResultSet rs)(Code) | | Close the given JDBC ResultSet and ignore any thrown exception.
This is useful for typical finally blocks in manual JDBC code.
Parameters: rs - the JDBC ResultSet to close (may be null ) |
closeStatement | public static void closeStatement(Statement stmt)(Code) | | Close the given JDBC Statement and ignore any thrown exception.
This is useful for typical finally blocks in manual JDBC code.
Parameters: stmt - the JDBC Statement to close (may be null ) |
extractDatabaseMetaData | public static Object extractDatabaseMetaData(DataSource dataSource, DatabaseMetaDataCallback action) throws MetaDataAccessException(Code) | | Extract database meta data via the given DatabaseMetaDataCallback.
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.
Parameters: dataSource - the DataSource to extract metadata for Parameters: action - callback that will do the actual work object containing the extracted information, as returned bythe DatabaseMetaDataCallback's processMetaData method throws: MetaDataAccessException - if meta data access failed |
extractDatabaseMetaData | public static Object extractDatabaseMetaData(DataSource dataSource, String metaDataMethodName) throws MetaDataAccessException(Code) | | Call the specified method on DatabaseMetaData for the given DataSource,
and extract the invocation result.
Parameters: dataSource - the DataSource to extract meta data for Parameters: metaDataMethodName - the name of the DatabaseMetaData method to call the object returned by the specified DatabaseMetaData method throws: MetaDataAccessException - if we couldn't access the DatabaseMetaDataor failed to invoke the specified method See Also: java.sql.DatabaseMetaData |
getResultSetValue | public static Object getResultSetValue(ResultSet rs, int index) throws SQLException(Code) | | Retrieve a JDBC column value from a ResultSet, using the most appropriate
value type. The returned value should be a detached value object, not having
any ties to the active ResultSet: in particular, it should not be a Blob or
Clob object but rather a byte array respectively String representation.
Uses the getObject(index) method, but includes additional "hacks"
to get around Oracle 10g returning a non-standard object for its TIMESTAMP
datatype and a java.sql.Date for DATE columns leaving out the
time portion: These columns will explicitly be extracted as standard
java.sql.Timestamp object.
Parameters: rs - is the ResultSet holding the data Parameters: index - is the column index the value object throws: SQLException - if thrown by the JDBC API See Also: java.sql.Blob See Also: java.sql.Clob See Also: java.sql.Timestamp |
isNumeric | public static boolean isNumeric(int sqlType)(Code) | | Check whether the given SQL type is numeric.
Parameters: sqlType - the SQL type to be checked whether the type is numeric |
supportsBatchUpdates | public static boolean supportsBatchUpdates(Connection con)(Code) | | Return whether the given JDBC driver supports JDBC 2.0 batch updates.
Typically invoked right before execution of a given set of statements:
to decide whether the set of SQL statements should be executed through
the JDBC 2.0 batch mechanism or simply in a traditional one-by-one fashion.
Logs a warning if the "supportsBatchUpdates" methods throws an exception
and simply returns false in that case.
Parameters: con - the Connection to check whether JDBC 2.0 batch updates are supported See Also: java.sql.DatabaseMetaData.supportsBatchUpdates |
|
|