|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jdbc.support.JdbcUtils
public abstract class JdbcUtils
Generic utility methods for working with JDBC. Mainly for internal use within the framework, but also useful for custom JDBC access code.
Field Summary | |
---|---|
static int |
TYPE_UNKNOWN
Constant that indicates an unknown (or unspecified) SQL type. |
Constructor Summary | |
---|---|
JdbcUtils()
|
Method Summary | |
---|---|
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. |
static Object |
getResultSetValue(ResultSet rs,
int index)
Retrieve a JDBC column value from a ResultSet, using the most appropriate value type. |
static boolean |
isNumeric(int sqlType)
Check whether the given SQL type is numeric. |
static boolean |
supportsBatchUpdates(Connection con)
Return whether the given JDBC driver supports JDBC 2.0 batch updates. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int TYPE_UNKNOWN
Types
,
Constant Field ValuesConstructor Detail |
---|
public JdbcUtils()
Method Detail |
---|
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 getResultSetValue(ResultSet rs, int index) throws SQLException
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.
rs
- is the ResultSet holding the dataindex
- is the column index
SQLException
- if thrown by the JDBC APIBlob
,
Clob
,
Timestamp
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 work
processMetaData
method
MetaDataAccessException
- 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 call
MetaDataAccessException
- if we couldn't access the DatabaseMetaData
or failed to invoke the specified methodDatabaseMetaData
public static boolean supportsBatchUpdates(Connection con)
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.
con
- the Connection to check
DatabaseMetaData.supportsBatchUpdates()
public static boolean isNumeric(int sqlType)
sqlType
- the SQL type to be checked
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |