| Bug #105912 | The client access database url is incomplete when using JDBC loadbalance mode | ||
|---|---|---|---|
| Submitted: | 16 Dec 2021 3:33 | Modified: | 28 Jan 2022 9:07 | 
| Reporter: | Zhihui Zhao | Email Updates: | |
| Status: | Can't repeat | Impact on me: | |
| Category: | Connector / J | Severity: | S3 (Non-critical) | 
| Version: | 5.1.49 | OS: | Linux | 
| Assigned to: | CPU Architecture: | Any | |
   [16 Dec 2021 6:43]
   MySQL Verification Team        
  Hello zhihui Zhao, Thank you for the report and test case. Observed that 5.1.49 is affected. Workaround is to use C/J 8.0.27 which don't have this issue. regards, Umesh
   [16 Dec 2021 6:55]
   MySQL Verification Team        
  Per https://dev.mysql.com/doc/relnotes/connector-j/5.1/en/ Support EOL for MySQL Connector/J 5.1 Per Oracle's Lifetime Support policy, as of Feb 9th, 2021, MySQL Connector/J 5.1 series is covered under Oracle Sustaining Support. Users are encouraged to upgrade to MySQL Connector/J 8.0 series. I'm afraid since 5.1 is EOL you may have to upgrade to C/J 8.0 in order to avoid this issue and this report may well be closed as won't fix.
   [28 Jan 2022 9:07]
   Alexander Soklakov        
  Posted by developer: This bug is not reproducible with the latest Connector/J 8.0. Connector/J 5.1 series came to EOL on Feb 9th, 2021, see https://www.mysql.com/support/eol-notice.html, so this bug will not be fixed there.


Description: When using a single data source with JDBC connection, such as “jdbc:mysql://$ip:$port/db?useUnicode=true&characterEncoding=utf-8”, the client can get complete url information. But if we use JDBC loadbalance mode to connect multiple data sources, such as "jdbc:mysql://$ip1:$port1,$ip2:$port2/db?useUnicode=true&characterEncoding=utf-8", the clinet can only get url like "dbc:mysql://$ip1:$port1/" or "dbc:mysql://$ip2:$port2/". How to repeat: //Testing code class DBUtil { static String userName="test"; static String password = "test"; // database static String url = "jdbc:mysql://$ip:$port/test?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&useSSL=false"; //static String url = "jdbc:mysql:loadbalance://$ip1:$port,$ip2:$port2/test?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&useSSL=false"; public static Connection getConnection() { Driver driver = null; try { Class<?> clazz = Class.forName("com.mysql.jdbc.Driver"); try { driver = (Driver) clazz.newInstance(); } catch (Exception e) { e.printStackTrace(); } } catch (ClassNotFoundException e) { e.printStackTrace(); } Properties props = new Properties(); props.setProperty("user", userName); props.setProperty("password", password); try { return driver.connect(url, props); } catch (SQLException e) { e.printStackTrace(); return null; } } } public class demo { public static void main(String[] args) { Connection conn = DBUtil.getConnection(); try { String dbUrl = conn.getMetaData().getURL(); System.out.println(dbUrl); } catch (SQLException e) { } } }