question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No suitable driver found for Postgresql with TestContainers since Quarkus 1.8

See original GitHub issue

Describe the bug

I have a TestContainers test that pings a Postgres DB. This test does not actually use Quarkus but I realized that it was working in 1.7.3 and failing in 1.8.

It is not a stopper for me (as I said, I realized I should have taken the @QuarkusTest annotation) but it sounds that something has been introduced that it makes this test fail (this test has been working since Quarkus 1.6 at least).

Expected behavior

The test should pass as in 1.7.3

Actual behavior

The test fail with:

java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:32831/vintageStoreDB?loggerLevel=OFF
        at org.acme.PingPostgreSQLTest.shouldPingPostgreSQL(PingPostgreSQLTest.java:32)

To Reproduce

Generate a brand new Quarkus 1.7.3-Final app with the Postgres extension. Then, add the TestContainers dependency:

  <properties>
   ...
    <testcontainers.version>1.14.3</testcontainers.version>
  </properties>

    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>postgresql</artifactId>
      <version>${testcontainers.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>junit-jupiter</artifactId>
      <version>${testcontainers.version}</version>
      <scope>test</scope>
    </dependency>

Now create a new Test

@QuarkusTest
@Testcontainers
public class PingPostgreSQLTest {

  @Container
  public static PostgreSQLContainer pg = new PostgreSQLContainer<>("postgres:12.4")
    .withDatabaseName("vintageStoreDB")
    .withUsername("vintage")
    .withPassword("vintage")
    .withExposedPorts(5432);

  @Test
  public void shouldPingPostgreSQL() throws Exception {
    pg.start();

    try (Connection con = DriverManager.getConnection(pg.getJdbcUrl(), pg.getUsername(), pg.getPassword());
         Statement st = con.createStatement();
         ResultSet rs = st.executeQuery("SELECT VERSION()")) {

      if (rs.next()) {
        assertTrue(rs.getString(1).contains("PostgreSQL 12"));
      } else {
        throw new Exception();
      }
    }

    pg.stop();
  }
}

This test just uses TestContainers to ping a Postgres db. It doesn’t use any Quarkus. In fact, if you leave the @QuarkusTest annotation it also works. Then, move to Quarkus 1.8.0, it fails.

Configuration

The test with 1.7.3 works even without any application.properties file declaring a Postgres driver or JDBC URL. Because it is now failing with 1.8 I tried to add quarkus.datasource.db-kind=postgresql and so on.

Environment (please complete the following information):

  • Output of uname -a or ver: Darwin iMac-Pro-de-Antonio.local 19.6.0 Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64 x86_64
  • Output of java -version: java version “11.0.6” 2020-01-14 LTS
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 1.8.0-Final
  • Build tool (ie. output of mvnw --version or gradlew --version): 3.6.3_1

Additional context (Add any other context about the problem here.)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
agoncalcommented, Oct 7, 2020

Just tested with Quarkus 1.8.2 and its ok now.

0reactions
agoncalcommented, Sep 18, 2020

Hum… I’ve tried to invoke DriverManager.getDrivers() before getting the connection, but it does not work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The infamous java.sql.SQLException: No suitable driver found
I'm trying to add a database-enabled JSP to an existing Tomcat 5.5 application (GeoServer 2.0.0, if that helps). The app itself talks to...
Read more >
Dev Services for Databases - Quarkus
Database Vendor Specific Configuration. All services based on containers are run using Testcontainers but Quarkus is not using the Testcontainers JDBC driver.
Read more >
Postgres No Suitable Driver Found - ADocLib
I am trying Kafka with Postgres Sink using JDBCsink connector. Exception: Unable to connect to database No suitable driver found for jdbc:postgresql #433....
Read more >
No suitable driver found when testing a PostgreSQL database ...
Issue. After creating a collector of DB Type: PostgreSQL in RSA Identity Governance & Lifecycle to collect data from a PostgreSQL database, the ......
Read more >
Custom configuration - Testcontainers for Java
compose.container.image = docker/compose:1.8.0 ... If your environment already implements automatic cleanup of containers after the execution, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found