Affects Version/s: 5.0.0
Fix Version/s: None
A MySQL database has multiple schemas: "dc", "rdc", "rdc_test" ...
The jdbc connection url is jdbc:mysql://192.168.1.199:3306/rdc_test?useUnicode=true...
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:
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.
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: