Issue
I'm working on a Java app, trying to create an instance of the OracleDataSource
. I've seen a bunch of posts saying the Oracle drivers aren't in Maven Central but according to this, they are now. So here's the dependency in my pom.xml
:
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
Then in my class I have:
import oracle.jdbc.driver.*;
import oracle.jdbc.pool.OracleDataSource;
...
public void someMethod() {
...
OracleDataSource ods = new OracleDataSource();
...
}
But I get errors saying neither the packages nor the class exist.
Error: package oracle.jdbc.pool does not exist.
Type 'OracleDataSource' not found
What am I missing here? It's been a while since I last worked with Java and Maven so I figure it's something simple.
EDIT The IDE (JDeveloper) and Maven seem to be out of sync. I'm getting different errors running Maven commands.
Solution
I tried the dependency and OracleDataSource instantiation as above and it compiled and ran in IntelliJ and on command line (mvn clean package) on Java 11.0.12-open, so I believe you are correct that the Oracle drivers are in Maven Central.
It may be an IDE issue - I sometimes find that IntelliJ's internal view of the project and dependencies is slightly out of kilter and either needs cache invalidation or careful gradual rebuild of any modules. I'm not sure what the equivalents are in JDeveloper.
However, generally the best way to deal with strange compilation issues is to first take the IDE out of the equation - try a mvn clean install
in the terminal. If that fails it may be worth moving your ~/.m2/repository
directory (or just the ~/.m2/repository/com.oracle
directory) and trying again in case a previous failure to retrieve artifacts has been cached. If it still fails then maybe check ~/.m2/settings.xml
to make sure it is pointing to maven central, but I'd expect it to find that driver okay.
Answered By - Chris
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)