postgresqlquarkusagroal

Unable to find a JDBC driver corresponding to the database kind 'postgresql' for the default


While connecting to postgres db from quarkus application but following error is thrown while building

2024-07-28 01:17:13,026 ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
    [error]: Build step io.quarkus.agroal.deployment.AgroalProcessor#build threw an exception: io.quarkus.runtime.configuration.ConfigurationException: Unable to find a JDBC driver corresponding to the database kind 'postgresql' for the default datasource (available: ''). Check if it's a typo, otherwise provide a suitable JDBC driver extension, define the driver manually, or disable the JDBC datasource by adding 'quarkus.datasource.jdbc=false' to your configuration if you don't need it.
    at io.quarkus.agroal.deployment.AgroalProcessor.resolveDriver(AgroalProcessor.java:371)
    at io.quarkus.agroal.deployment.AgroalProcessor.getAggregatedConfigBuildItems(AgroalProcessor.java:345)
    at io.quarkus.agroal.deployment.AgroalProcessor.build(AgroalProcessor.java:102)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:849)
    at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
    at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
    at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
    at java.base/java.lang.Thread.run(Thread.java:1583)
    at org.jboss.threads.JBossThread.run(JBossThread.java:483)

build.gradle

dependencies {
    implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
    implementation 'io.quarkus:quarkus-rest'
    implementation 'io.quarkus:quarkus-arc'
    testImplementation 'io.quarkus:quarkus-junit5'
    testImplementation 'io.rest-assured:rest-assured'
    implementation 'io.quarkus:quarkus-agroal'


    implementation "org.postgresql:postgresql:${postgreDriverVersion}" //postgreDriverVersion=42.7.3

}

application.properties

quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=postgres
quarkus.datasource.password=admin
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost/sample
quarkus.datasource.jdbc.min-size=3
quarkus.datasource.jdbc.max-size=13

code

package com.pruthvi.sample.config;

import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

@ApplicationScoped
public class DatabaseConfig {
    @Inject
    DataSource dataSource;

    private Connection connection;

    @PostConstruct
    public void init() {
        try {
            this.connection = dataSource.getConnection();
        } catch (SQLException e) {
            throw new RuntimeException("Failed to initialize database connection", e);
        }
    }

    public Connection getConnection() {
        return this.connection;
    }
}

I am following the official tutorial https://quarkus.io/guides/datasource And it seems everyting is right? could someone help to find why this issue is occuring.


Solution

  • As far as I can tell from the description, you are missing the quarkus-jdbc-postgresql dependency.

    Also note that if you add it, you don't need to add the agroal or org.postgresql:postgresql dependencies