Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-188

Default pool framework initialisation

    XMLWordPrintable

Details

    • Task
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • 1.2.0
    • 1.2.2
    • Other
    • None

    Description

      (report from github https://github.com/MariaDB/mariadb-connector-j/issues/35 from ocafebabe)

      Some database connection pool like the one I use (Oracle UCP) will set default values for the serverName and port properties (in this case: null and 0) in org.mariadb.jdbc.MySQLDataSource.

      So even though the URL I set is valid, the connection will fail because the two properties were overridden and the generated URL by the datasource implementation is then invalid: jdbc:mysql://address=(host=null)(port=0)(type=master)

      PoolDataSource pds = oracle.ucp.jdbc.PoolDataSourceFactory.getPoolDataSource();
      pds.setConnectionFactoryClassName("org.mariadb.jdbc.MySQLDataSource");
      pds.setURL("jdbc:mysql://localhost:3306/testdb");
      pds.setUser("test");
      pds.setPassword("test");
       
      Connection c = pds.getConnection();

      java.sql.SQLException: Exception occurred while getting connection: oracle.ucp.UniversalConnectionPoolException: Cannot get Connection from Datasource: java.lang.IllegalArgumentException: hostname can't be null
      Would it be possible to add two validation checks in org.mariadb.jdbc.MySQLDataSource as follow:

       
      public void setServerName(String serverName) {
          if (serverName != null && !serverName.isEmpty()) {
              jdbcUrl.getHostAddresses().get(0).host = serverName;
          }
      }
       
      public void setPort(int p) {
          if (p > 0) {
              jdbcUrl.getHostAddresses().get(0).port = p;
          }
      }

      These validation checks are pretty generic and I don't think it would be harmful under other circumstances!

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            diego dupin Diego Dupin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.