apache/beam · error · IllegalArgumentException

JDBC type must be one of ${JDBC_DRIVER_MAP.keySet()} but was

Error message

JDBC type must be one of ${JDBC_DRIVER_MAP.keySet()} but was ${jdbcType}

What it means

When a jdbcType IS provided, it must match a key in the provider's JDBC_DRIVER_MAP (case-insensitive). An unknown value like "postgresql" or "pg" when the map expects "postgres" throws this IllegalArgumentException listing the valid keys.

Source

Thrown at sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcWriteSchemaTransformProvider.java:407

        throw new IllegalArgumentException("JDBC URL cannot be blank");
      }

      jdbcType = !Strings.isNullOrEmpty(jdbcType) ? jdbcType : getJdbcType();

      boolean driverClassNamePresent = !Strings.isNullOrEmpty(getDriverClassName());
      boolean driverJarsPresent = !Strings.isNullOrEmpty(getDriverJars());
      boolean jdbcTypePresent = !Strings.isNullOrEmpty(jdbcType);
      if (!driverClassNamePresent && !driverJarsPresent && !jdbcTypePresent) {
        throw new IllegalArgumentException(
            "If JDBC type is not specified, then Driver Class Name and Driver Jars must be specified.");
      }
      if (!driverClassNamePresent && !jdbcTypePresent) {
        throw new IllegalArgumentException(
            "One of JDBC Driver class name or JDBC type must be specified.");
      }
      if (jdbcTypePresent
          && !JDBC_DRIVER_MAP.containsKey(Objects.requireNonNull(jdbcType).toLowerCase())) {
        throw new IllegalArgumentException(
            "JDBC type must be one of " + JDBC_DRIVER_MAP.keySet() + " but was " + jdbcType);
      }

      boolean writeStatementPresent =
          (getWriteStatement() != null && !"".equals(getWriteStatement()));
      boolean locationPresent = (getLocation() != null && !"".equals(getLocation()));

      if (writeStatementPresent && locationPresent) {
        throw new IllegalArgumentException(
            "Write Statement and Table are mutually exclusive configurations");
      }
      if (!writeStatementPresent && !locationPresent) {
        throw new IllegalArgumentException("Either Write Statement or Table must be set.");
      }
    }

    public static Builder builder() {
      return new AutoValue_JdbcWriteSchemaTransformProvider_JdbcWriteSchemaTransformConfiguration

View on GitHub (pinned to 12126d8942)

Solutions

  1. Use one of the supported keys exactly as printed in the error message (e.g. "postgres", "mysql", "mssql", "oracle")
  2. Lowercase the value before passing it if it comes from user input (comparison is case-insensitive, but spelling must match)
  3. For unsupported databases, switch to driverClassName + driverJars instead of jdbcType

Example fix

// before
builder().setJdbcType("postgresql").build();
// after
builder().setJdbcType("postgres").build();
Defensive patterns

Strategy: validation

Validate before calling

Set<String> allowed = Set.of("postgres", "mysql", "mssql", "oracle"); // mirrors JDBC_DRIVER_MAP keys
if (jdbcType != null && !allowed.contains(jdbcType.toLowerCase())) {
  throw new IllegalArgumentException("Unsupported jdbcType: " + jdbcType);
}

Try / catch

try {
  config.validate();
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("JDBC type must be one of")) {
    LOG.error("Use one of the listed jdbcType keys: {}", e.getMessage());
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling validate() with jdbcType set to a string not contained (after lowercasing) in JDBC_DRIVER_MAP keySet, e.g. "postgresql", "sqlserver", "db2".

Common situations: Typos or synonyms: "postgresql" instead of "postgres"; using a driver family Beam's map does not include; passing a URL fragment as jdbcType by mistake.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/cbaa99a98b0573a9. Report an issue: GitHub.