public static String pingJdbcEndpoint ( MuleContext muleContext , String muleJdbcDataSourceName , String tableName ) { DataSource ds = JdbcUtil . lookupDataSource ( muleContext , muleJdbcDataSourceName ) ; Connection c = null ; Statement s = null ; ResultSet rs = null ; try { c = ds . getConnection ( ) ; s = c . createStatement ( ) ; rs = s . executeQuery ( "select 1 from " + tableName ) ; } catch ( SQLException e ) { return ERROR_PREFIX + ": The table " + tableName + " was not found in the data source " + muleJdbcDataSourceName + ", reason: " + e . getMessage ( ) ; } finally { try { if ( rs != null ) rs . close ( ) ; } catch ( SQLException e ) { } try { if ( s != null ) s . close ( ) ; } catch ( SQLException e ) { } try { if ( c != null ) c . close ( ) ; } catch ( SQLException e ) { } } return OK_PREFIX + ": The table " + tableName + " was found in the data source " + muleJdbcDataSourceName ; }
Verify access to a JDBC endpoint by verifying that a specified table is accessible .