{"record":{"id":"a8858e1b77a99489","repo":"jd-opensource/joyagent-jdgenie","slug":"error-a8858e","errorCode":null,"errorMessage":"获取数据库表失败","messagePattern":"获取数据库表失败","errorType":"exception","errorClass":"CatalogException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/data/jdbc/catalog/mysql/MySqlCatalog.java","lineNumber":45,"sourceCode":"        SYS_DATABASES.add(\"mysql\");\n        SYS_DATABASES.add(\"performance_schema\");\n        SYS_DATABASES.add(\"sys\");\n    }\n\n    @Override\n    public List<SimpleTable> listTables(Connection connection, String schema) throws CatalogException {\n        String sql = \"show tables \";\n        try (PreparedStatement prepared = connection.prepareStatement(sql);\n             ResultSet rs = prepared.executeQuery()) {\n            List<SimpleTable> tables = new ArrayList<>();\n            while (rs.next()) {\n                SimpleTable st = new SimpleTable();\n                st.setTableName(rs.getString(1));\n                tables.add(st);\n            }\n            return tables;\n        } catch (SQLException e) {\n            throw new CatalogException(\"获取数据库表失败\", e);\n        }\n    }\n\n    public String typeConvertMysql(String type) {\n        return switch (type) {\n            case \"DATE\", \"TIME\", \"TIMESTAMP\" -> StandardColumnType.DATE.name();\n            case \"TINYINT\", \"SMALLINT\", \"INTEGER\", \"BIGINT\", \"FLOAT\", \"DOUBLE\", \"NUMERIC\", \"DECIMAL\" ->\n                    StandardColumnType.DECIMAL.name();\n            default -> StandardColumnType.VARCHAR.name();\n        };\n    }\n\n    @Override\n    public List<TableColumn> getTableColumns(Connection connection, String tablePath, String schema) throws CatalogException {\n        String sql = String.format(\n                SELECT_COLUMNS_SQL_TEMPLATE, schema, tablePath);\n\n        try (Statement prepared = connection.createStatement();","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/data/jdbc/catalog/mysql/MySqlCatalog.java#L27-L63","documentation":"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.","triggerScenarios":"Calling listTables(schema) when the MySQL connection fails, the database/schema does not exist, or the metadata query throws an SQLException.","commonSituations":"Unknown database after a config change, MySQL server down or credentials rotated, user lacking SHOW TABLES privileges, or network/firewall blocking port 3306.","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."],"exampleFix":"// before\ncatalog.listTables(\"MyDB\"); // MySQL on Linux is case-sensitive\n// after\ncatalog.listTables(\"mydb\"); // match lower_case_table_names setting","handlingStrategy":"retry","validationCode":"// Java: pre-check database exists\ntry (Connection c = DriverManager.getConnection(url, user, pass)) {\n    ResultSet rs = c.createStatement().executeQuery(\"SHOW DATABASES LIKE '\" + schema + \"'\");\n    if (!rs.next()) throw new IllegalStateException(\"database not found: \" + schema);\n}","typeGuard":null,"tryCatchPattern":"try {\n    List<SimpleTable> tables = mySqlCatalog.listTables(schema);\n} catch (CatalogException e) {\n    if (e.getCause() instanceof SQLException sql &&\n        \"08001\".equals(sql.getSQLState())) {\n        // transient connectivity: retry with backoff\n    } else throw e;\n}","preventionTips":["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."],"tags":["jdbc","mysql","catalog","sql"],"backgroundTag":"database-query-failed","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}