{"record":{"id":"8388ac396a086e4b","repo":"apache/shardingsphere","slug":"5-8388ac","errorCode":"5","errorMessage":"Underlying SQL state: %s, underlying error code: %s.","messagePattern":"Underlying SQL state: (.+?), underlying error code: (.+?)\\.","errorType":"exception","errorClass":"SQLWrapperException","httpStatus":null,"severity":"critical","filePath":"infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java","lineNumber":103,"sourceCode":"    \n    private static Map<String, DataSource> getDataSources(final DatabaseConfiguration databaseConfig) {\n        return databaseConfig.getStorageUnits().entrySet().stream()\n                .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));\n    }\n    \n    /**\n     * Get storage type.\n     *\n     * @param dataSource data source\n     * @return storage type\n     * @throws SQLWrapperException SQL wrapper exception\n     * @throws RuntimeException Runtime exception\n     */\n    public static DatabaseType getStorageType(final DataSource dataSource) {\n        try (Connection connection = dataSource.getConnection()) {\n            return DatabaseTypeFactory.get(connection.getMetaData());\n        } catch (final SQLException ex) {\n            throw new SQLWrapperException(ex);\n        }\n    }\n    \n    /**\n     * Get default storage type.\n     *\n     * @return default storage type\n     */\n    public static DatabaseType getDefaultStorageType() {\n        return TypedSPILoader.getService(DatabaseType.class, DEFAULT_DATABASE_TYPE);\n    }\n}\n","sourceCodeStart":85,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java#L85-L116","documentation":"SQLWrapperException thrown by DatabaseTypeEngine.getStorageType when opening a connection to the provided DataSource to read database metadata fails: dataSource.getConnection() or metadata access throws SQLException, which is wrapped (message surfaces the underlying SQLState and vendor error code). This utility resolves the storage DatabaseType by connecting once; failure usually means the data source itself is unreachable or misconfigured.","triggerScenarios":"Calling contexts that resolve a storage type from a raw DataSource (e.g. adding a storage unit, JDBC mode metadata loading) when the database is down, credentials are wrong, URL/driver is invalid, or a pool rejects the connection (timeout, pool exhausted).","commonSituations":"Startup or REGISTER STORAGE UNIT with an unreachable DB host; wrong username/password; JDBC URL with bad syntax or missing driver on the classpath; network/firewall blocking the database port; connection-pool limits hit during metadata refresh.","solutions":["Verify connectivity with the same URL/credentials outside ShardingSphere (e.g. a plain JDBC probe or psql/mysql client).","Fix the data source configuration: URL syntax, driver class, username/password, and make sure the driver jar is on the classpath.","If the failure is transient (pool exhaustion, brief outage), retry the operation after the database is reachable.","Check the wrapped SQLException's SQLState/error code in the cause chain for the database's specific reason."],"exampleFix":"# before: unreachable host / bad credentials\nurl: jdbc:postgresql://db.prod.internal:5432/shop?user=app&password=wrong\n\n# after: verified reachable host and credentials\nurl: jdbc:postgresql://db.prod.internal:5432/shop\nusername: app\npassword: correct_secret","handlingStrategy":"retry","validationCode":"// Probe connectivity before asking ShardingSphere to resolve the storage type\ntry (Connection c = dataSource.getConnection();\n     var stmt = c.createStatement();\n     var rs = stmt.executeQuery(\"SELECT 1\")) {\n    // reachable — safe to proceed\n} catch (SQLException e) {\n    throw new IllegalStateException(\"Storage unit unreachable: \" + jdbcUrl, e);\n}","typeGuard":null,"tryCatchPattern":"int attempts = 0;\nwhile (true) {\n    try {\n        return DatabaseTypeEngine.getStorageType(dataSource);\n    } catch (final SQLWrapperException ex) {\n        SQLException cause = (SQLException) ex.getCause();\n        if (++attempts >= 3 || !isTransient(cause)) { throw ex; }\n        backoff(attempts);\n    }\n}","preventionTips":["Pre-flight-check all storage units (host, port, credentials, driver on classpath) before startup or REGISTER STORAGE UNIT.","Keep the cause chain intact — the underlying SQLState/vendor code identifies the real failure.","Use short connection timeouts so unreachable databases fail fast during metadata resolution."],"tags":["infra","database-type","connection","sql-exception","startup"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}