jd-opensource/joyagent-jdgenie · error · CatalogException
获取数据库表失败
Error message
获取数据库表失败
What it means
MySqlCatalog.listTables wraps any SQLException from the MySQL metadata query into CatalogException '获取数据库表失败'. It means listing tables in a MySQL database failed at JDBC level; the original SQLException is the cause.
Solutions
- Verify the database exists (SHOW DATABASES) and the name is correct.
- Test connectivity/credentials (mysql client or ping to host:3306).
- Inspect the cause SQLException for the MySQL error code.
- GRANT the user SELECT/SHOW privileges on the target schema.
Example fix
// before
catalog.listTables("MyDB"); // MySQL on Linux is case-sensitive
// after
catalog.listTables("mydb"); // match lower_case_table_names setting Defensive patterns
Strategy: retry
Validate before calling
// Java: pre-check database exists
try (Connection c = DriverManager.getConnection(url, user, pass)) {
ResultSet rs = c.createStatement().executeQuery("SHOW DATABASES LIKE '" + schema + "'");
if (!rs.next()) throw new IllegalStateException("database not found: " + schema);
} Try / catch
try {
List<SimpleTable> tables = mySqlCatalog.listTables(schema);
} catch (CatalogException e) {
if (e.getCause() instanceof SQLException sql &&
"08001".equals(sql.getSQLState())) {
// transient connectivity: retry with backoff
} else throw e;
} Prevention
- Validate schema names against SHOW DATABASES in config checks.
- Rotate credentials centrally so catalog and app stay in sync.
- Grant SHOW/SELECT privileges to the service account.
- Mind case sensitivity on Linux MySQL servers.
When it happens
Trigger: Calling listTables(schema) when the MySQL connection fails, the database/schema does not exist, or the metadata query throws an SQLException.
Common situations: Unknown database after a config change, MySQL server down or credentials rotated, user lacking SHOW TABLES privileges, or network/firewall blocking port 3306.
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
- 获取数据库表失败
- 获取表字段信息失败
- Failed listing database in catalog
- Failed getting table
- Could not find any jdbc dialect factory that can handled
AI-assisted analysis of jd-opensource/joyagent-jdgenie@2417e0b8b6 (2026-09-08).
Data as JSON: /api/errors/a8858e1b77a99489.
Report an issue: GitHub.
Appendix: source
Thrown at genie-backend/src/main/java/com/jd/genie/data/jdbc/catalog/mysql/MySqlCatalog.java:45
SYS_DATABASES.add("mysql");
SYS_DATABASES.add("performance_schema");
SYS_DATABASES.add("sys");
}
@Override
public List<SimpleTable> listTables(Connection connection, String schema) throws CatalogException {
String sql = "show tables ";
try (PreparedStatement prepared = connection.prepareStatement(sql);
ResultSet rs = prepared.executeQuery()) {
List<SimpleTable> tables = new ArrayList<>();
while (rs.next()) {
SimpleTable st = new SimpleTable();
st.setTableName(rs.getString(1));
tables.add(st);
}
return tables;
} catch (SQLException e) {
throw new CatalogException("获取数据库表失败", e);
}
}
public String typeConvertMysql(String type) {
return switch (type) {
case "DATE", "TIME", "TIMESTAMP" -> StandardColumnType.DATE.name();
case "TINYINT", "SMALLINT", "INTEGER", "BIGINT", "FLOAT", "DOUBLE", "NUMERIC", "DECIMAL" ->
StandardColumnType.DECIMAL.name();
default -> StandardColumnType.VARCHAR.name();
};
}
@Override
public List<TableColumn> getTableColumns(Connection connection, String tablePath, String schema) throws CatalogException {
String sql = String.format(
SELECT_COLUMNS_SQL_TEMPLATE, schema, tablePath);
try (Statement prepared = connection.createStatement();View on GitHub (pinned to 2417e0b8b6)