{"record":{"id":"605e2bbf76dd6bfb","repo":"mybatis/mybatis-3","slug":"error-occurred-when-getting-db-product-name","errorCode":null,"errorMessage":"Error occurred when getting DB product name.","messagePattern":"Error occurred when getting DB product name\\.","errorType":"exception","errorClass":"BuilderException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/mapping/VendorDatabaseIdProvider.java","lineNumber":47,"sourceCode":" * It returns database product name as a databaseId. If the user provides a properties it uses it to translate database\n * product name key=\"Microsoft SQL Server\", value=\"ms\" will return \"ms\". It can return null, if no database product name\n * or a properties was specified and no translation was found.\n *\n * @author Eduardo Macarron\n */\npublic class VendorDatabaseIdProvider implements DatabaseIdProvider {\n\n  private Properties properties;\n\n  @Override\n  public String getDatabaseId(DataSource dataSource) {\n    if (dataSource == null) {\n      throw new NullPointerException(\"dataSource cannot be null\");\n    }\n    try {\n      return getDatabaseName(dataSource);\n    } catch (SQLException e) {\n      throw new BuilderException(\"Error occurred when getting DB product name.\", e);\n    }\n  }\n\n  @Override\n  public void setProperties(Properties p) {\n    this.properties = p;\n  }\n\n  private String getDatabaseName(DataSource dataSource) throws SQLException {\n    String productName = getDatabaseProductName(dataSource);\n    if (properties == null || properties.isEmpty()) {\n      return productName;\n    }\n    return properties.entrySet().stream().filter(entry -> productName.contains((String) entry.getKey()))\n        .map(entry -> (String) entry.getValue()).findFirst().orElse(null);\n  }\n\n  private String getDatabaseProductName(DataSource dataSource) throws SQLException {","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/mapping/VendorDatabaseIdProvider.java#L29-L65","documentation":"VendorDatabaseIdProvider wraps any SQLException raised while fetching the database product name into a BuilderException. Resolving databaseId requires a live connection (Connection.getMetaData().getDatabaseProductName()), so connection failures surface here during startup.","triggerScenarios":"A databaseIdProvider is configured and MyBatis opens a connection to identify the DB, but the JDBC URL, driver, credentials, or network are wrong; the pool rejects the connection.","commonSituations":"Bad JDBC URL or missing driver on classpath; DB unreachable from the build/deploy environment; credentials changed; connection pool max-size exhausted at startup.","solutions":["Verify the DataSource can open a connection with the same settings outside MyBatis (e.g. a plain JDBC snippet).","Check the JDBC URL, driver class, and credentials in the environment block.","Fix network/firewall access to the database host and port.","Temporarily remove the <databaseIdProvider> element to confirm it is the failing component."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"try (Connection c = dataSource.getConnection()) {\n  c.getMetaData().getDatabaseProductName(); // proves connectivity before MyBatis startup\n}","typeGuard":null,"tryCatchPattern":"try {\n  sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);\n} catch (BuilderException e) {\n  if (e.getMessage().contains(\"DB product name\")) {\n    // surface as environment/config problem: check URL, driver, credentials\n  }\n  throw e;\n}","preventionTips":["Smoke-test DataSource connectivity in a startup healthcheck before building the SqlSessionFactory.","Keep databaseIdProvider properties (product-name mappings) in externalized config so DB swaps need no code change."],"tags":["mybatis","jdbc","connection","databaseid","startup"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}