Uploaded image for project: 'Apache MetaModel'
  1. Apache MetaModel
  2. METAMODEL-1191

JdbcDataContext get wrong schema name on MySQL

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments


    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 5.0.0
    • Fix Version/s: None
    • Labels:
    • Environment:
      MySQL 8.0


      A MySQL database has multiple schemas: "dc", "rdc", "rdc_test" ...

      The jdbc connection url is jdbc:mysql://

      When use JdbcDataContext.getDefaultSchemaName() to obtain the default schema,

      we expected this function to return "rdc_test",which is the part of connection url, but it returns "dc". 

      After debug, we found the issue is caused by following code:

      JdbcDataContext.java  Line 672:


      for (int i = 0; i < schemaNames.size() && !found; i++) {
          String schemaName = schemaNames.get(i);
          if (lastToken.indexOf(schemaName) != -1) {
              result = schemaName;
              found = true;


      Here the lastToken is "rdc_test?useUnicode=....." which is extracted from url, it's correct. When use indexOf() to match schemaNames array, the first schema "dc" is matched and returned.

      The most simplest solution I think is to get the longest schema which is a part of lastToken. Below is the fixed code. We tested it and works fine.


      for (int i = 0; i < schemaNames.size(); i++) {
          String schemaName = schemaNames.get(i);
          if (lastToken.indexOf(schemaName) != -1) {
              if (result == null) {
                  result = schemaName;
              } else {
                  result = schemaName.length() > result.length() ? schemaName : result;
              found = true;


      Consider the same string with schema name may also appears in the right part of '?' character, is it better to use startWith() instead of indexOf()? Like this:

      if (lastToken.startWith(schemaName)) 









            • Assignee:
              hling Hao Ling


              • Created:

                Issue deployment