Skip to content

JdbcDatabaseContainer. constructUrlForConnection() returning malformed URLs #1976

Closed
@mahwy

Description

@mahwy

JdbcDatabaseContainer. constructUrlForConnection() is a simple method that concatenates JDBC URL and a query string starting with ?.

protected String constructUrlForConnection(String queryString) {
return getJdbcUrl() + queryString;
}

But PostgreSQLContainer. getJdbcUrl () returns a JDBC URL with the query string ?loggerLevel=OFF (The change was introduced from this PR: https://github.com/testcontainers/testcontainers-java/pull/1434/files#diff-d62130004eb8d994f60b87f95b1488be)

return "jdbc:postgresql://" + getContainerIpAddress() + ":" + getMappedPort(POSTGRESQL_PORT) + "/" + databaseName + "?loggerLevel=OFF";

This returns invalid URLs for PostgreSQLContainers with custom parameters. For example, given the following URL:
jdbc:tc:fevopostgresql:9.6.11://hostname/databasename?stringtype=unspecified,
the produced connection URL is
jdbc:postgresql://localhost:32793/databasename?loggerLevel=OFF?stringtype=unspecified instead of ...&stringtype=unspecified

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions