[CONJ-188] Default pool framework initialisation Created: 2015-08-31  Updated: 2015-09-02  Resolved: 2015-09-02

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.2.0
Fix Version/s: 1.2.2

Type: Task Priority: Minor
Reporter: Diego Dupin Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: 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!


Generated at Thu Feb 08 03:13:50 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.