apache/seatunnel · error · CatalogException

查询数据库是否存在失败:

Error message

查询数据库是否存在失败: 

What it means

KingbaseCatalog.databaseExists wraps any SQLException from the database-existence query into CatalogException("查询数据库是否存在失败: <databaseName>") ("Failed to check whether database exists"). The concrete JDBC error is the chained cause.

Source

Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/kingbase/KingbaseCatalog.java:158

     * Override the databaseExists method because SELECT current_database() does not support WHERE
     */
    @Override
    public boolean databaseExists(String databaseName) throws CatalogException {
        if (StringUtils.isBlank(databaseName)) {
            return false;
        }
        try {
            return querySQLResultExists(getUrlFromDatabaseName(databaseName), getListDatabaseSql());
        } catch (SeaTunnelRuntimeException e) {
            if (e.getSeaTunnelErrorCode().getCode().equals(UNSUPPORTED_METHOD.getCode())) {
                log.warn(
                        "The catalog: {} is not supported the getListDatabaseSql for databaseExists",
                        this.catalogName);
                return listDatabases().contains(databaseName);
            }
            throw e;
        } catch (SQLException e) {
            throw new CatalogException("查询数据库是否存在失败: " + databaseName, e);
        }
    }

    @Override
    protected String getCreateTableSql(
            TablePath tablePath, CatalogTable table, boolean createIndex) {
        return new KingbaseCreateTableSqlBuilder(table, createIndex).build(tablePath);
    }

    @Override
    protected String getDropTableSql(TablePath tablePath) {
        return String.format("DROP TABLE %s", tablePath.getSchemaAndTableName("\""));
    }

    @Override
    protected String getListTableSql(String databaseName) {
        return "SELECT SCHEMANAME ,TABLENAME FROM SYS_TABLES";
    }

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Inspect the chained cause (getCause) for the underlying SQLException
  2. Verify connectivity/credentials to the Kingbase server with a standalone JDBC client
  3. Confirm the database name is valid and properly escaped
  4. Check the Kingbase version supports the SQL used by getListDatabaseSql / existence query
  5. Grant the catalog user permission to read system catalogs (e.g. pg_database equivalents)

Example fix

// before
boolean exists = catalog.databaseExists(dbName); // CatalogException with Chinese msg
// after
try {
    boolean exists = catalog.databaseExists(dbName);
} catch (CatalogException e) {
    LOG.error("databaseExists {} failed: {}", dbName, e.getCause());
    throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

try (Connection c = DriverManager.getConnection(kingbaseUrl, user, pass)) {
    if (!c.isValid(5)) throw new IllegalStateException("Kingbase connection invalid");
}

Try / catch

try {
    boolean exists = catalog.databaseExists(dbName);
} catch (CatalogException e) {
    LOG.error("Kingbase databaseExists({}) failed: {}", dbName, e.getCause(), e);
    throw e;
}

Prevention

When it happens

Trigger: Calling databaseExists(name) (directly or via framework pre-checks) when the SQL query against the Kingbase server throws SQLException: server unreachable, wrong credentials, invalid database name characters, or the existence-check SQL is unsupported by the Kingbase version.

Common situations: Kingbase (人大金仓) server down or wrong port; user lacking privileges to query system databases; database name with special characters breaking the query; Kingbase version whose system catalog differs from the assumed SQL.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/dec71460f4484c23. Report an issue: GitHub.