{"record":{"id":"363b55f9e6c86816","repo":"YunaiV/ruoyi-vue-pro","slug":"exception-while-initializing-database-connection","errorCode":null,"errorMessage":"Exception while initializing Database connection","messagePattern":"Exception while initializing Database connection","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"sql/dm/flowable-patch/src/main/java/org/flowable/common/engine/impl/AbstractEngineConfiguration.java","lineNumber":527,"sourceCode":"                    if (resultSet.next()) {\n                        version = resultSet.getString(\"version\");\n                    }\n\n                    if (StringUtils.isNotEmpty(version) && version.toLowerCase().startsWith(PRODUCT_NAME_CRDB.toLowerCase())) {\n                        databaseProductName = PRODUCT_NAME_CRDB;\n                        logger.info(\"CockroachDB version '{}' detected\", version);\n                    }\n                }\n            }\n\n            databaseType = databaseTypeMappings.getProperty(databaseProductName);\n            if (databaseType == null) {\n                throw new FlowableException(\"couldn't deduct database type from database product name '\" + databaseProductName + \"'\");\n            }\n            logger.debug(\"using database type: {}\", databaseType);\n\n        } catch (SQLException e) {\n            throw new RuntimeException(\"Exception while initializing Database connection\", e);\n        } finally {\n            try {\n                if (connection != null) {\n                    connection.close();\n                }\n            } catch (SQLException e) {\n                logger.error(\"Exception while closing the Database connection\", e);\n            }\n        }\n\n        // Special care for MSSQL, as it has a hard limit of 2000 params per statement (incl bulk statement).\n        // Especially with executions, with 100 as default, this limit is passed.\n        if (DATABASE_TYPE_MSSQL.equals(databaseType)) {\n            maxNrOfStatementsInBulkInsert = DEFAULT_MAX_NR_OF_STATEMENTS_BULK_INSERT_SQL_SERVER;\n        }\n    }\n\n    public void initSchemaManager() {","sourceCodeStart":509,"sourceCodeEnd":545,"githubUrl":"https://github.com/YunaiV/ruoyi-vue-pro/blob/0418084e222612af2fc1141f566af454f9236ab1/sql/dm/flowable-patch/src/main/java/org/flowable/common/engine/impl/AbstractEngineConfiguration.java#L509-L545","documentation":"During database type detection Flowable opens a Connection, calls getMetaData(), and (for Postgres) runs 'select version()'. Any SQLException in that block is caught and rethrown as a RuntimeException with this message and the original SQLException as cause. It signals the connection itself is broken during the metadata probe.","triggerScenarios":"The connection is invalid mid-init (closed by pool, network blip, DB still starting); the Postgres 'select version()' query fails due to permissions; metadata calls raise SQLFeatureNotSupportedException on a thin driver.","commonSituations":"CI races where Flowable inits before the DB accepts queries; read-only DB user lacking SELECT on version(); driver incompatibility (older driver vs newer DB) causing SQLException on metadata.","solutions":["Inspect the caused-by SQLException for SQLState/vendor code to pinpoint the failing metadata call.","Ensure the DB user has the necessary privileges (at least CONNECT and SELECT on system/version functions).","Add a connection-readiness wait before Flowable engine init.","Use a JDBC driver version compatible with the target DB server version."],"exampleFix":"// before: init immediately, races with DB startup\nprocessEngine = cfg.buildProcessEngine();\n// after: wait for connectivity first\nwhile (!dataSource.getConnection().isValid(2)) { /* readiness wait */ }\nprocessEngine = cfg.buildProcessEngine();","handlingStrategy":"retry","validationCode":"try (Connection c = dataSource.getConnection()) {\n    if (!c.isValid(2)) throw new IllegalStateException(\"DB connection not valid\");\n    c.getMetaData().getDatabaseProductName();\n} catch (SQLException e) { throw new IllegalStateException(\"DB not ready\", e); }","typeGuard":"null","tryCatchPattern":"try { engine = cfg.buildProcessEngine(); }\ncatch (RuntimeException e) {\n    if (e.getCause() instanceof SQLException) { /* wait for DB readiness, retry once */ }\n    throw e;\n}","preventionTips":["Add a connection readiness wait before engine init","Grant the DB user SELECT on version()/system functions","Use a JDBC driver version compatible with the DB server"],"tags":["flowable","database-connection","metadata","runtime"],"backgroundTag":null,"analyzedSha":"0418084e222612af2fc1141f566af454f9236ab1","analyzedAt":"2026-08-14T00:56:18.412Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}