oracle / oracle-r2dbc

R2DBC Driver for Oracle Database
https://oracle.com
Other
197 stars 40 forks source link

Oracle Driver Not Found - While Deploying in Tomcat Application Server #142

Closed nmsundar-coder closed 6 months ago

nmsundar-coder commented 6 months ago

I am facing an issue while deploying spring boot application with oracle-r2dbc .

Error :

Caused by: java.sql.SQLException: No suitable driver at java.sql/java.sql.DriverManager.getDriver(DriverManager.java:299) at oracle.r2dbc.impl.ReactiveJdbcAdapter.getOracleAdapter(ReactiveJdbcAdapter.java:89)

Application.yml

r2dbc: url: r2dbc:oracle://localhost:1521/DBNAME username: admin password: password pool: enabled: false

Pom.xml

org.springframework.boot spring-boot-starter-data-r2dbc 3.2.3
    <dependency>
        <groupId>com.oracle.database.r2dbc</groupId>
        <artifactId>oracle-r2dbc</artifactId>
    </dependency>
Michael-A-McMahon commented 6 months ago

Thanks for reporting this.

The error is most likely caused by the ojdbc11 jar not being present in the class path or module path of the JVM. The call to DriverManager.getDriver(String) is searching for JDBC drivers on the class/module path, and testing if they recognize "jdbc:oracle:thin:" as a supported URL. If Oracle JDBC is there (ie: if the ojdbc11 jar is there), then we shouldn't see "No suitable driver".

Can you check the class/module path of your application to verify if ojdbc11 is present?

Michael-A-McMahon commented 6 months ago

@nmsundar-coder Thanks for sharing the demo code. I will continue to investigate. I noticed there was a username and password within the file, so I deleted the message just to be safe.

Michael-A-McMahon commented 6 months ago

I tried running this little test in a maven project with a copy of your pom.xml:

import io.r2dbc.spi.*;
import reactor.core.publisher.Flux;

public class Test {

  public static void main(String[] args) {
    ConnectionFactory connectionFactory =
      ConnectionFactories.get("r2dbc:oracle://localhost:1521/DBNAME");

    Connection connection =
      Flux.from(connectionFactory.create()).blockFirst();

    System.out.println("Connected!");

    Flux.from(connection.close()).blockFirst();
  }

}

I was not able to reproduce the same error though.

I'm wondering: It looks like you might be using r2dbc-pool (which is excellent), but I think it may require a URL which looks like this: r2dbc:pool:oracle://localhost:1521/DBNAME. Have you tried doing that?

Michael-A-McMahon commented 6 months ago

I'm also wondering if this has something to do with war file packaging. I actually have no experience with war files, but Wikipedia says a war file is a way to combine many jar files into one file. So I'm wondering how that would handle a META-INF/services/java.sql.Driver file. That file exists in the ojdbc11 jar, but how would it be transferred into the war file? What if there are multiple JDBC driver jars going into the war file? Do each of their META-INF/services/java.sql.Driver files get concatenated into one? Seems like a tough problem to solve.

The error we are seeing could happen if ServiceLoader is not finding the META-INF/services/java.sql.Driver file from the ojdbc11 jar. See "Deploying service providers on the class path" here: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/ServiceLoader.html

nmsundar-coder commented 6 months ago

Thanks @Michael-A-McMahon

Found the issue, I have to set up classpath driver jar file and ignore building it along by war packaging. Thanks for the prompt response and efforts.

Michael-A-McMahon commented 6 months ago

Glad you got it figured out! Thanks for sharing the solution too; This can help others who hit the same problem.

Michael-A-McMahon commented 6 months ago

@nmsundar-coder I checked with Oracle's GitHub team about the demo zip you had shared yesterday. We strongly recommend that you change the password which appeared in that zip. Because the message attachment was public, it is possible that someone could have obtained a copy and will be able to get into your system. I hope this advice will help. Thanks!