Reputation: 3848
Am trying to use jdbc connection in my Java EE6 application(class name VisualizerRepository.java), i have the jdbc driver in nexus repository
The class has to execute a stored procedure and print the result of the procedure. Since JPA 2.0 has no support on calling procedures am using jdbc.
package com.nfsmith.crm.data.repository;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import oracle.jdbc.OracleTypes;
import org.jboss.logging.Logger;
@Named
@ApplicationScoped
public class VisualizerRepository
{
DataSource datasource;
Connection connection;
CallableStatement statement;
@PostConstruct
public void initDBConnection()
{
InitialContext context;
try
{
context = new InitialContext();
datasource = (DataSource) context.lookup("java:jboss/datasources/partmatchDatasource");
connection = null;
statement = null;
connection = datasource.getConnection();
}
catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void getJSonDataList()
{
try {
statement = connection.prepareCall("{call crm.PKG_CRM_RELATIONSHIP.getOrgViewDataJason(?,?,?)}");
int owner = 48156;
statement.setInt(1, owner);
int site = 10;
statement.setInt(2, site);
statement.registerOutParameter(3, OracleTypes.CURSOR);
statement.execute();
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
statement.close();
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
when I do the build am seeing the compilation error saying package oracle.jdbc does not exist and cannot find symbol
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/rpalle/workspace/CRM/smith-crm-web/src/main/java/com/nfsmith/crm/data/repository/VisualizerRepository.java:[15,19] package oracle.jdbc does not exist
[ERROR] /C:/Users/rpalle/workspace/CRM/smith-crm-web/src/main/java/com/nfsmith/crm/data/repository/VisualizerRepository.java:[66,51] cannot find symbol
symbol: variable OracleTypes
location: class com.nfsmith.crm.data.repository.VisualizerRepository
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Smith CRM ......................................... SUCCESS [0.823s]
[INFO] Smith CRM Web ..................................... FAILURE [4.775s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.410s
[INFO] Finished at: Wed Aug 07 13:48:32 CDT 2013
[INFO] Final Memory: 36M/530M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "CRM_local" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project smith-crm-web: Compilation failure: Compilation failure:
[ERROR] /C:/Users/rpalle/workspace/CRM/smith-crm-web/src/main/java/com/nfsmith/crm/data/repository/VisualizerRepository.java:[15,19] package oracle.jdbc does not exist
[ERROR] /C:/Users/rpalle/workspace/CRM/smith-crm-web/src/main/java/com/nfsmith/crm/data/repository/VisualizerRepository.java:[66,51] cannot find symbol
[ERROR] symbol: variable OracleTypes
[ERROR] location: class com.nfsmith.crm.data.repository.VisualizerRepository
[ERROR] -> [Help 1]
Upvotes: 10
Views: 30520
Reputation: 453
I faced a similar scenario where exception was following.
java: cannot access oracle.jdbc.OracleTypes error
I manually installed ojdbc JAR to my local repository. However the problem was still existing. It was because I installed ojbc10.jar. For some reasons I thought number in this JAR name is like JDBC version. But they are more related with Java version. My project was using Java JDK 8. So issue got resolved after installing ojdbc8.jar.
So when you download make sure to check the release note. Certified with JDK8, JDK9, JDK11.
Upvotes: 0
Reputation: 4436
I tried to get gradle to pull the jar from my local maven repo and even using flatDir
in the repositories
closure, but to no effect. In the end, I created a lib
folder in my project and put the jar in it and added
dependencies {
...
compile files('lib/ojdbc7.jar')
...
}
I don't think this is the prettiest way to handle it, but it worked, and it's good enough for now.
Upvotes: 0
Reputation: 1338
Oracle JDBC drivers are accessible from Oracle Maven Repository with some additional security related steps.
Check the blog "Get Oracle JDBC drivers and UCP from Oracle Maven Repository (without IDEs)" for more details.
Upvotes: 3
Reputation: 16
The maven command that resides in answer
(meanwhile it was taken from http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/) did not work for me. But after removing {}
characters, everything is fine:
mvn install:install-file -Dfile=Path/to/your/ojdbc.jar -DgroupId=com.oracle
-DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
Also don't forget to add version number to the name of jar file like ojdb6-11.2.0.jar
Upvotes: -1
Reputation: 483
The ojdbc jar is not in public maven repositories. You can add the jar to local repository manually.
Download the jar from:
Install in your repository
mvn install:install-file -Dfile={Path/to/your/ojdbc.jar} -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
Use in your pom
<dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0</version> </dependency>
Upvotes: 17