Here is a JDBC URL that works, as expected:
jdbc:tc:postgresql:10.14:///test
This will start a container and when org.testcontainers.containers.JdbcDatabaseContainer::constructUrlForConnection is called you will get
jdbc:postgresql://localhost:32845/test?loggerLevel=OFF
That's a legit JDBC url to connect to once the container is started. Everything works as expected.
Let's try to add a parameter to configure the postgresql JDBC connection:
jdbc:tc:postgresql:10.14:///test?preparedStatementCacheQueries=0
This does not work as expected because the generated JDBC URL for the container will be:
jdbc:postgresql://localhost:32845/test?loggerLevel=OFF?preparedStatementCacheQueries=0
There is two ? so JDBC driver fail to open a connection.
This is because org.testcontainers.containers.PostgreSQLContainer::getJdbcUrl add its own query string:
@Override
public String getJdbcUrl() {
// Disable Postgres driver use of java.util.logging to reduce noise at startup time
return "jdbc:postgresql://" + getContainerIpAddress() + ":" + getMappedPort(POSTGRESQL_PORT) + "/" + databaseName + "?loggerLevel=OFF";
}
@numero-six what version of Testcontainers are you using? I should be fixed already
It was 1.12.1, using 1.15.0 solve the issue. Thanks @bsideup and sorry for the noise :sweat: (I did not found the issue)!