{"record":{"id":"524141e32b00a69c","repo":"jd-opensource/joyagent-jdgenie","slug":"failed-listing-database-in-catalog-s","errorCode":null,"errorMessage":"Failed listing database in catalog %s","messagePattern":"Failed listing database in catalog (.+?)","errorType":"exception","errorClass":"CatalogException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/data/jdbc/catalog/AbstractJdbcCatalog.java","lineNumber":40,"sourceCode":"    public List<SimpleTable> listTables(Connection connection, String schema) throws CatalogException {\n        try (ResultSet rs = connection.getMetaData().getTables(null,\n                schema, null, null)) {\n            List<SimpleTable> tables = new ArrayList<>();\n            while (rs.next()) {\n                SimpleTable st = new SimpleTable();\n                st.setTableName(rs.getString(\"TABLE_NAME\"));\n                st.setComments(rs.getString(\"REMARKS\"));\n                st.setTableType(rs.getString(\"TABLE_TYPE\"));\n                String tableSchem = rs.getString(\"TABLE_SCHEM\");\n                if (StringUtils.isBlank(tableSchem)) {\n                    tableSchem = rs.getString(\"TABLE_CAT\");\n                }\n                st.setTableSchema(tableSchem);\n                tables.add(st);\n            }\n            return tables;\n        } catch (SQLException e) {\n            throw new CatalogException(\"Failed listing database in catalog %s\", e);\n        }\n    }\n\n\n    @Override\n    public List<TableColumn>  getTableColumns(Connection connection, String tablePath, String schema) throws CatalogException {\n        try (ResultSet rs = connection.getMetaData().getColumns(null,\n                null, tablePath, null)) {\n\n            List<TableColumn> columnList = new ArrayList<>();\n            while (rs.next()) {\n                String name = rs.getString(\"COLUMN_NAME\");\n                int intDataType = rs.getInt(\"DATA_TYPE\");\n                JDBCType jdbcType = JDBCType.valueOf(intDataType);\n                String dataType = typeConvert(jdbcType);\n\n                TableColumn column = TableColumn.builder().name(name)\n                        .columnLength(rs.getInt(\"COLUMN_SIZE\"))","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/data/jdbc/catalog/AbstractJdbcCatalog.java#L22-L58","documentation":"AbstractJdbcCatalog.listTables wraps any SQLException raised while querying the JDBC DatabaseMetaData for tables into a CatalogException with a generic 'Failed listing database in catalog %s' message. It signals that catalog metadata discovery via JDBC failed.","triggerScenarios":"listTables invoked with a connection whose metadata query throws SQLException — bad connection state, wrong schema/tableType filters, driver incompatibility, or the underlying database rejecting the metadata query.","commonSituations":"Connection closed or timed out before the call; driver doesn't support the expected DatabaseMetaData API shape; wrong case-sensitivity for schema names (e.g., Oracle uppercase); missing privileges to list tables.","solutions":["Inspect the wrapped SQLException cause for the real driver error code/message.","Verify the JDBC connection is open and valid before listing (connection.isValid).","Check schema name casing and user privileges on the target database.","Confirm the JDBC driver version matches the database server version."],"exampleFix":"// before\n} catch (SQLException e) {\n    throw new CatalogException(\"Failed listing database in catalog %s\", e);\n}\n// after\n} catch (SQLException e) {\n    throw new CatalogException(\"Failed listing tables in catalog, schema=\" + tableSchem\n        + \", sqlState=\" + e.getSQLState(), e);\n}","handlingStrategy":"try-catch","validationCode":"if (connection == null || !connection.isValid(2)) {\n    throw new IllegalStateException(\"JDBC connection not valid before listTables\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    catalog.listTables(conn, schema);\n} catch (CatalogException e) {\n    Throwable cause = e.getCause();\n    if (cause instanceof SQLException sql) {\n        // inspect sql.getSQLState()/getErrorCode() to retry vs fail\n    }\n    throw e;\n}","preventionTips":["Validate/renew the connection before metadata queries.","Match schema name casing to the database's rules.","Grant metadata read privileges to the DB user.","Keep the JDBC driver version aligned with the server."],"tags":["java","jdbc","catalog","database"],"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"}