List of usage examples for org.springframework.jdbc.support MetaDataAccessException MetaDataAccessException
public MetaDataAccessException(String msg, Throwable cause)
From source file:org.springframework.jdbc.support.JdbcUtils.java
/** * Call the specified method on DatabaseMetaData for the given DataSource, * and extract the invocation result./*from ww w.ja v a 2s . c om*/ * @param dataSource the DataSource to extract meta data for * @param metaDataMethodName the name of the DatabaseMetaData method to call * @return the object returned by the specified DatabaseMetaData method * @throws MetaDataAccessException if we couldn't access the DatabaseMetaData * or failed to invoke the specified method * @see java.sql.DatabaseMetaData */ @SuppressWarnings("unchecked") public static <T> T extractDatabaseMetaData(DataSource dataSource, final String metaDataMethodName) throws MetaDataAccessException { return (T) extractDatabaseMetaData(dataSource, dbmd -> { try { Method method = DatabaseMetaData.class.getMethod(metaDataMethodName, (Class[]) null); return method.invoke(dbmd, (Object[]) null); } catch (NoSuchMethodException ex) { throw new MetaDataAccessException("No method named '" + metaDataMethodName + "' found on DatabaseMetaData instance [" + dbmd + "]", ex); } catch (IllegalAccessException ex) { throw new MetaDataAccessException( "Could not access DatabaseMetaData method '" + metaDataMethodName + "'", ex); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof SQLException) { throw (SQLException) ex.getTargetException(); } throw new MetaDataAccessException( "Invocation of DatabaseMetaData method '" + metaDataMethodName + "' failed", ex); } }); }