Java Maven ojdbc jar依赖错误:包oracle.jdbc不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18111646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:28:24  来源:igfitidea点击:

Maven ojdbc jar dependency error: package oracle.jdbc does not exist

javasqlmavenjdbcjava-ee-6

提问by RanPaul

Heading

标题

Am trying to use jdbc connection in my Java EE6 application(class name VisualizerRepository.java), i have the jdbc driver in nexus repository

我正在尝试在我的 Java EE6 应用程序(类名 VisualizerRepository.java)中使用 jdbc 连接,我在 nexus 存储库中有 jdbc 驱动程序

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.

该类必须执行一个存储过程并打印该过程的结果。由于 JPA 2.0 不支持使用 jdbc 调用过程。

package com.nfsmith.crm.data.repository;

包 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

当我进行构建时,我看到编译错误说 package oracle.jdbc 不存在并且找不到符号

[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]

采纳答案by Sergio Puas

The ojdbc jar is not in public maven repositories. You can add the jar to local repository manually.

ojdbc jar 不在公共 maven 存储库中。您可以手动将 jar 添加到本地存储库。

Download the jar from:

从以下位置下载 jar:

  • oracle site
  • copy from your oracle database server ( {ORACLE_HOME}\jdbc\lib\ojdbc6.jar)
  • 甲骨文网站
  • 从您的 oracle 数据库服务器复制 ( {ORACLE_HOME}\jdbc\lib\ojdbc6.jar)

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

在你的 pom 中使用

   <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0</version>
   </dependency>
   <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0</version>
   </dependency>

回答by y?lmaz

The maven command that resides in answer

驻留在 answer 中的 maven 命令

(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:

(同时它取自http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/)对我不起作用。但是删除{}字符后,一切都很好:

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

也不要忘记将版本号添加到 jar 文件的名称中,例如 ojdb6-11.2.0.jar

回答by Nirmala

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.

Oracle JDBC 驱动程序可以从 Oracle Maven Repository 访问,并执行一些额外的安全相关步骤。
查看博客“从 Oracle Maven 存储库(无 IDE)获取 Oracle JDBC 驱动程序和 UCP”以获取更多详细信息。