pentaho/pentaho-kettle · warning · KettleDatabaseException

Error closing prepared statement

Error message

Error closing prepared statement

What it means

KettleDatabaseException thrown by Database.closePreparedStatement(PreparedStatement) when ps.close() throws a SQLException. Purely a resource-release failure; the statement is being discarded anyway, so this usually signals a broken connection or driver quirk rather than lost data. Also reached via closeLookup()/closeInsert().

Solutions

  1. Treat as non-fatal in cleanup paths: log and continue, since the statement is being released regardless
  2. Check connection health; if the connection is dead, close/reconnect the whole Database object
  3. Upgrade the driver if it throws spuriously on close
  4. Ensure statements are closed before the connection so close order is correct

Example fix

// before
try { database.closeInsert(); } finally { database.disconnect(); }
// after
try {
  database.closeInsert();
} catch ( KettleDatabaseException e ) {
  log.warn("Failed to close prepared statement: " + e.getMessage());
} finally {
  database.disconnect();
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  database.closePreparedStatement( ps );
} catch ( KettleDatabaseException e ) {
  log.warn( "Statement close failed (non-fatal): " + e.getMessage() );
}

Prevention

When it happens

Trigger: Calling closePreparedStatement(ps) (or closeLookup/closeInsert) where ps.close() throws SQLException — connection already dead, driver-specific close failure, or double-close issues in some drivers.

Common situations: Cleanup in error paths after the DB connection dropped, drivers that throw on closing statements of a terminated session.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


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

Appendix: source

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

      }
    } catch ( SQLException ex ) {
      throw new KettleDatabaseException( "Couldn't prepare statement:" + Const.CR + sql, ex );
    }
  }

  public void closeLookup() throws KettleDatabaseException {
    if ( pstmt != null ) {
      closePreparedStatement( pstmt );
      pstmt = null;
    }
  }

  public void closePreparedStatement( PreparedStatement ps ) throws KettleDatabaseException {
    if ( ps != null ) {
      try {
        ps.close();
      } catch ( SQLException e ) {
        throw new KettleDatabaseException( "Error closing prepared statement", e );
      }
    }
  }

  /**
   * Invokes the {@link AutoCloseable#close()} method on the given object, logging any exceptions that occur.
   *
   * @param closeable      the object to close
   * @param objDescription the description of the closeable object, used in logging
   */
  protected void tryCloseAndLog( AutoCloseable closeable, String objDescription ) {
    try {
      closeable.close();
    } catch ( Exception ex ) {
      log.logError( "Error closing " + objDescription + ":" + Const.CR + ex.getMessage() );
      log.logError( Const.getStackTracker( ex ) );
    }
  }

View on GitHub (pinned to f3058517a1)