alibaba/druid · error · SQLException

xa not support dbType : {dbTypeName}

Error message

xa not support dbType : {dbTypeName}

What it means

DruidXADataSource.createPhysicalXAConnection() throws this when DbType.of(this.dbTypeName) returns null — i.e. the configured dbTypeName could not be mapped to any known DbType enum value. Because XA connection creation is dispatched per-database (Oracle, MySQL, PostgreSQL, H2, jtds, DM, OceanBase), an unrecognized dbType has no XA factory to use. This fires at the top of the switch, before any case is selected.

Source

Thrown at core/src/main/java/com/alibaba/druid/pool/xa/DruidXADataSource.java:66

        XAConnection rawXAConnection = createPhysicalXAConnection(physicalConn);

        return new DruidPooledXAConnection(conn, rawXAConnection);
    }

    protected void initCheck() throws SQLException {
        super.initCheck();

        DbType dbType = DbType.of(this.dbTypeName);
        if (JdbcUtils.H2.equals(dbType)) {
            h2Factory = H2Utils.createJdbcDataSourceFactory();
        }
    }

    private XAConnection createPhysicalXAConnection(Connection physicalConn) throws SQLException {
        DbType dbType = DbType.of(this.dbTypeName);

        if (dbType == null) {
            throw new SQLException("xa not support dbType : " + this.dbTypeName);
        }

        switch (dbType) {
            case oracle:
                try {
                    return OracleUtils.OracleXAConnection(physicalConn);
                } catch (XAException xae) {
                    LOG.error("create xaConnection error", xae);
                    return null;
                }
            case mysql:
            case mariadb:
                return MySqlUtils.createXAConnection(driver, physicalConn);
            case postgresql:
                return PGUtils.createXAConnection(physicalConn);
            case h2:
                return H2Utils.createXAConnection(h2Factory, physicalConn);
            case jtds:

View on GitHub (pinned to fa8dc99126)

Solutions

  1. Set dbTypeName explicitly to a supported value, e.g. dataSource.setDbType("mysql"); supported XA types: oracle, mysql, mariadb, postgresql, h2, jtds, dm, oceanbase, oceanbase_oracle.
  2. If your database is unsupported for XA, do not use DruidXADataSource — use the regular DruidDataSource and a non-XA transaction manager.
  3. Print the actual dbTypeName at startup to catch null/empty/whitespace values quickly.

Example fix

// before
DruidXADataSource ds = new DruidXADataSource();
ds.setUrl("jdbc:mysql://db:3306/app");
// dbTypeName not set -> DbType.of(null) == null
XAConnection xa = ds.getXAConnection(); // throws 'xa not support dbType : null'

// after
DruidXADataSource ds = new DruidXADataSource();
ds.setUrl("jdbc:mysql://db:3306/app");
ds.setDbType("mysql");
XAConnection xa = ds.getXAConnection();
Defensive patterns

Strategy: validation

Validate before calling

DruidXADataSource xa = ...;
if (xa.getDbTypeName() == null || DbType.of(xa.getDbTypeName()) == null) {
    throw new IllegalStateException("set dbTypeName to a supported value before getXAConnection()");
}

Type guard

public static boolean xaSupportedDbType(String dbTypeName) {
    DbType t = DbType.of(dbTypeName);
    return t != null && java.util.EnumSet.of(
        DbType.oracle, DbType.mysql, DbType.mariadb, DbType.postgresql,
        DbType.h2, DbType.jtds, DbType.dm, DbType.oceanbase, DbType.oceanbase_oracle
    ).contains(t);
}

Prevention

When it happens

Trigger: Calling getXAConnection() on a DruidXADataSource whose dbTypeName is null, empty, or a value Druid cannot resolve (e.g. a misspelled or newly-introduced database name, or an unset dbType).

Common situations: Forgetting to set dbTypeName on DruidXADataSource; using a JDBC URL whose scheme Druid does not auto-detect to a DbType; pointing at a database (e.g. a NoSQL or unsupported engine) for which Druid has no XA support.

Related errors


AI-assisted analysis of alibaba/druid@fa8dc99126 (2026-08-14). Data as JSON: /api/errors/f64aae13c34981b8. Report an issue: GitHub.