pentaho/pentaho-kettle · error · KettleDatabaseException

Error occurred while trying to retrieve the DataSource

Error message

Error occurred while trying to retrieve the DataSource

What it means

initializeConnectionDataSource wraps failures while obtaining a DataSource (JNDI lookup or pooled lookup through the DataSourceProviderInterface) into KettleDatabaseException("Error occurred while trying to retrieve the DataSource", cause). It is thrown when getJNDIDataSource or getPoolingDataSource raises any exception.

Solutions

  1. Inspect the cause chain for the underlying JNDI or provider exception
  2. Verify the JNDI datasource name matches one defined in the container (jdbc.properties / context.xml)
  3. If not using JNDI, confirm connection pool settings and that the provider supports pooled lookups
  4. Fall back to Native (JDBC) access type if DataSource retrieval is not required

Example fix

// before
DataSource ds = db.getDataSource(); // throws wrapped error

// after
try {
  DataSource ds = db.getDataSource();
} catch ( KettleDatabaseException e ) {
  log.error( "DataSource lookup failed: " + e.getCause(), e );
}
Defensive patterns

Strategy: try-catch

Validate before calling

if ( dbMeta.getAccessType() == DatabaseMeta.TYPE_ACCESS_JNDI ) {
  // confirm the JNDI name is defined in the container before lookup
  validateJndiNameExists( dbMeta.getDatabaseName() );
}

Try / catch

try {
  DataSource ds = db.getDataSource();
} catch ( KettleDatabaseException e ) {
  log.error( "DataSource retrieval failed: " + e.getCause(), e );
}

Prevention

When it happens

Trigger: Calling getDataSource()/initializeConnectionDataSource when access type is JNDI but the JNDI lookup fails, or when using a connection pool and DataSourceProviderInterface throws (e.g. naming exceptions, unsupported-operation stubs from errors 140/141).

Common situations: Misconfigured JNDI name in DatabaseMeta, missing JNDI server/properties file, custom DataSourceProviderInterface throwing, or pooled datasource provisioning failures in the app server.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/e9e2650fe3d2bc24. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/pentaho/di/core/database/Database.java:552

  }

  public void initializeConnectionDataSource( String partitionId ) throws KettleDatabaseException {

    try {
      DataSourceProviderInterface dsp = DataSourceProviderFactory.getDataSourceProviderInterface();
      if ( dsp == null ) {
        // since DataSourceProviderFactory is initialised with new DatabaseUtil(),
        // this assignment is correct
        dsp = new DatabaseUtil();
      }

      if ( databaseMeta.getAccessType() == DatabaseMeta.TYPE_ACCESS_JNDI ) {
        this.dataSource = getJNDIDataSource( dsp );
      } else if ( databaseMeta.isUsingConnectionPool() ) {
        this.dataSource = getPoolingDataSource( partitionId, dsp );
      }
    } catch ( Exception e ) {
      throw new KettleDatabaseException( "Error occurred while trying to retrieve the DataSource", e );
    }
  }

  private DataSource getPoolingDataSource( String partitionId, DataSourceProviderInterface dsp ) throws Exception {

    try {
      return dsp.getPooledDataSourceFromMeta( databaseMeta, DatasourceType.POOLED );
    } catch ( UnsupportedOperationException e ) {
      // UnsupportedOperationException is happen at DatabaseUtil doesn't support pooled DS, use legacy routine
      // NullPointerException is happen when we will try to run the transformation on the remote server but
      // server does not have such databases, so will using legacy routine as well
      if ( databaseMeta.isNeedUpdate() && !ConnectionPoolUtil.hasOldConfig( databaseMeta, partitionId ) ) {
        dsp.invalidateNamedDataSource( ConnectionPoolUtil.getDataSourceName( databaseMeta, partitionId ),
          DatasourceType.POOLED );
        databaseMeta.setNeedUpdate( false );
      }
      return ConnectionPoolUtil.getDataSource( log, databaseMeta, partitionId );
    }

View on GitHub (pinned to f3058517a1)