alibaba/spring-ai-alibaba · error · IllegalArgumentException

Unsupported dbType: {dbType}. Supported values: mysql, postg

Error message

Unsupported dbType: {dbType}. Supported values: mysql, postgresql, oracle, h2

What it means

DatabaseStore.buildJdbcUrl switches on the configured dbType and throws IllegalArgumentException for any value outside mysql, postgresql/postgres/pgsql, oracle, and h2. The dbType comes from store configuration; a typo or unsupported database means no JDBC URL can be constructed.

Source

Thrown at spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/DatabaseStore.java:192

     * Build a JDBC URL from simple connection parameters.
     *
     * @param dbType   database type
     * @param host     database host
     * @param port     database port
     * @param database database name (or service name for Oracle)
     * @return normalized JDBC URL
     */
    public static String buildJdbcUrl(String dbType, String host, int port, String database) {
        validateConnectionInfo(dbType, host, port, database);
        String normalized = dbType.trim().toLowerCase(Locale.ROOT);
        return switch (normalized) {
            // MySQL supports optional auto database creation via URL parameters.
            case "mysql" -> "jdbc:mysql://" + host + ":" + port + "/" + database
                    + "?createDatabaseIfNotExist=true&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
            case "postgresql", "postgres", "pgsql" -> "jdbc:postgresql://" + host + ":" + port + "/" + database;
            case "oracle" -> "jdbc:oracle:thin:@" + host + ":" + port + ":" + database;
            case "h2" -> "jdbc:h2:mem:" + database + ";DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE";
            default -> throw new IllegalArgumentException(
                    "Unsupported dbType: " + dbType + ". Supported values: mysql, postgresql, oracle, h2");
        };
    }

    /**
     * Validate connection parameters for JDBC URL construction.
     *
     * @param dbType   database type
     * @param host     database host
     * @param port     database port
     * @param database database name
     */
    private static void validateConnectionInfo(String dbType, String host, int port, String database) {
        if (dbType == null || dbType.isBlank()) {
            throw new IllegalArgumentException("dbType cannot be null or blank");
        }
        if (host == null || host.isBlank()) {
            throw new IllegalArgumentException("host cannot be null or blank");

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Set dbType to exactly one of: mysql, postgresql (or postgres/pgsql), oracle, h2 — lowercase.
  2. Normalize/trim the dbType config value before constructing DatabaseStore.
  3. For an unsupported database, switch to a supported one (e.g. H2 for testing, PostgreSQL for production) or provide a custom Store implementation.
  4. Catch IllegalArgumentException at startup and fail fast with the list of supported values.

Example fix

// before
DatabaseStore store = DatabaseStore.builder()
        .dbType(config.get("db_type")) // "PostgreSQL"
        ...
// after
String dbType = config.get("db_type").trim().toLowerCase();
if (!Set.of("mysql", "postgresql", "postgres", "pgsql", "oracle", "h2").contains(dbType)) {
    throw new IllegalArgumentException("Unsupported dbType: " + dbType);
}
DatabaseStore store = DatabaseStore.builder().dbType(dbType)...
Defensive patterns

Strategy: validation

Validate before calling

Set<String> SUPPORTED = Set.of("mysql", "postgresql", "postgres", "pgsql", "oracle", "h2");
String dbType = cfg.dbType() == null ? null : cfg.dbType().trim().toLowerCase();
if (dbType == null || !SUPPORTED.contains(dbType)) {
    throw new IllegalArgumentException("dbType must be one of " + SUPPORTED);
}
DatabaseStore store = DatabaseStore.builder().dbType(dbType).build();

Type guard

boolean isSupportedDbType(String t) {
    return t != null && Set.of("mysql", "postgresql", "postgres", "pgsql", "oracle", "h2").contains(t.trim().toLowerCase());
}

Try / catch

try {
    DatabaseStore store = DatabaseStore.builder().dbType(cfg.dbType()).build();
} catch (IllegalArgumentException e) {
    throw new IllegalStateException("Bad dbType in config: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Configuring DatabaseStore with dbType values like "MySQL" (uppercase), "mariadb", "sqlserver", "db2", or any misspelling; the switch's default branch fires when jdbcUrl is built.

Common situations: Case-sensitivity mistakes ("PostgreSQL" instead of "postgresql"); attempting to use an unsupported database (SQL Server, SQLite, MariaDB); config from environment variables with wrong values; docs referencing dialect names not in the supported list.

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 alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/30bc4acb56928e80. Report an issue: GitHub.