List of usage examples for org.springframework.jdbc.support MetaDataAccessException MetaDataAccessException
public MetaDataAccessException(String msg)
From source file:org.springframework.jdbc.support.JdbcUtils.java
/** * Extract database meta data via the given DatabaseMetaDataCallback. * <p>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. * <p>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. * @param dataSource the DataSource to extract metadata for * @param action callback that will do the actual work * @return object containing the extracted information, as returned by * the DatabaseMetaDataCallback's {@code processMetaData} method * @throws MetaDataAccessException if meta data access failed *//*from www. j a va2 s . c o m*/ public static Object extractDatabaseMetaData(DataSource dataSource, DatabaseMetaDataCallback action) throws MetaDataAccessException { Connection con = null; try { con = DataSourceUtils.getConnection(dataSource); DatabaseMetaData metaData = con.getMetaData(); if (metaData == null) { // should only happen in test environments throw new MetaDataAccessException("DatabaseMetaData returned by Connection [" + con + "] was null"); } return action.processMetaData(metaData); } catch (CannotGetJdbcConnectionException ex) { throw new MetaDataAccessException("Could not get Connection for extracting meta data", ex); } catch (SQLException ex) { throw new MetaDataAccessException("Error while extracting DatabaseMetaData", ex); } catch (AbstractMethodError err) { throw new MetaDataAccessException( "JDBC DatabaseMetaData method not implemented by JDBC driver - upgrade your driver", err); } finally { DataSourceUtils.releaseConnection(con, dataSource); } }