找不到 JDBC 驱动程序类:oracle.jdbc.OracleDriver
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7478454/
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
JDBC Driver class not found: oracle.jdbc.OracleDriver
提问by Phoenix
I have installed a third party java webservice which uses Oralce jdbc thin driver to write data into Oracle database. When i run this, i get the following error;
我安装了第三方 java webservice,它使用 Oralce jdbc 瘦驱动程序将数据写入 Oracle 数据库。当我运行它时,出现以下错误;
JDBC Driver class not found: oracle.jdbc.OracleDriver
找不到 JDBC 驱动程序类:oracle.jdbc.OracleDriver
I have oracle installed and set classpath variable to following value:
我安装了 oracle 并将类路径变量设置为以下值:
*D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.zip;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.zip;C:\Program Files\Java\jdk1.7.0\jre\lib\rt.jar*
*D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.zip;D:\oracle\product\ 10.2.0\client_1\jdbc\lib\ojdbc14.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.zip;C:\Program Files\Java\jdk1.7.0\jre\lib \rt.jar*
and path variable to following value;
和路径变量到以下值;
*D:\oracle\product\10.2.0\client_1\bin;C:\Program Files\Java\jdk1.7.0\bin\;D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.zip;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.zip*
*D:\oracle\product\10.2.0\client_1\bin;C:\Program Files\Java\jdk1.7.0\bin\;D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12. jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.zip;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.jar;D:\oracle\product \10.2.0\client_1\jdbc\lib\ojdbc14.zip*
Any suggestion why web service is not able to identify jdbc driver?
为什么 Web 服务无法识别 jdbc 驱动程序的任何建议?
Thanks
谢谢
采纳答案by Micha? Niklas
I know 2 ways of turning Java app into Windows service and both do not use CLASSPATH
. One is Java Service Wrapper by Tanuki Software. This tool uses wrapper.conf
where you can show directories with .jar
libraries:
我知道 2 种将 Java 应用程序转换为 Windows 服务的方法,并且都不使用CLASSPATH
. 一种是Tanuki Software 的 Java Service Wrapper。此工具使用wrapper.conf
您可以显示带有.jar
库的目录的位置:
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
wrapper.java.classpath.1=c:\jars\*
wrapper.java.classpath.2=myservice.jar
Second tool I know is JSL: Java Service Launcher. In this tool there is jsl.ini
where you put command line to run your server. It can use java with -cp
option to show location of .jar
libraries:
我知道的第二个工具是JSL:Java Service Launcher。在此工具中jsl.ini
,您可以放置命令行来运行服务器。它可以使用带有-cp
选项的java来显示.jar
库的位置:
[defines]
MY_LIBS=d:\jars\*
AXIS_LIBS=d:\axis2-1.5.4\lib\*
CLASSPATH=.;%MY_LIBS%;%AXIS_LIBS%
export = CLASSPATH
...
[java]
...
cmdline = -Dfile.encoding=utf8 -cp %CLASSPATH% example.my.server
In both configuration you can use *
to add all .jar
files or you can show those files one by one (just like in CLASSPATH
).
在这两种配置中,您都可以*
用来添加所有.jar
文件,也可以一个一个地显示这些文件(就像在 中一样CLASSPATH
)。
At first you should know what Windows is trying to execute. Check it in the service properties page. Then try to localize its configuration. If it uses one of tools I know then you know what to change. Other tools probably have similar configuration.
首先,您应该知道 Windows 试图执行什么。在服务属性页面中检查它。然后尝试本地化其配置。如果它使用我知道的工具之一,那么您就知道要更改什么。其他工具可能有类似的配置。
回答by Ayush Srivastava
Method 1: Download ojdbc.jar
方法一:下载ojdbc.jar
add ojdbc6.jar to deployment assembly. Right click on project->properties->select deployment assembly->click on 'Add' ->select 'Archives from File System'->browse to the folder where ojdbc6.jar is saved.->add the jar->click finish->Apply/OK.
将 ojdbc6.jar 添加到部署程序集。右键项目->属性->选择部署程序集->点击'添加'->选择'Archives from File System'->浏览到保存ojdbc6.jar的文件夹->添加jar->点击完成-> 应用/确定。
Method 2:
方法二:
if you want to add ojdbc.jar to your maven dependencies you follow this link: http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/. . Even if you're using a maven project it is not necessary to add ojdbc to maven dependencies(method 2), method 1 (adding directly to deployment assembly) works just fine.
如果您想将 ojdbc.jar 添加到您的 maven 依赖项,请点击此链接:http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository /. . 即使您使用的是 maven 项目,也没有必要将 ojdbc 添加到 maven 依赖项(方法 2),方法 1(直接添加到部署程序集)工作得很好。
回答by grepit
Make sure you have the ojdbc jar file (make sure you are using the correct one because depending on java version you may need to choose a different one).
确保您有 ojdbc jar 文件(确保您使用的是正确的文件,因为根据 Java 版本,您可能需要选择不同的文件)。
use ojdbc14.jar for Java 1.4 use ojdbc5.jar for Java 1.5 ojdbc6.jar for Java 1.6 here is linke where you can download ojdbc6.jar file http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html
使用 ojdbc14.jar for Java 1.4 使用 ojdbc5.jar for Java 1.5 ojdbc6.jar for Java 1.6 这里是链接,您可以下载 ojdbc6.jar 文件 http://www.oracle.com/technetwork/database/enterprise-edition/jdbc -112010-090769.html
回答by montjoile
You also have to add the jdbc jar to your server classpath. if tomcat, rigth-click on your Project->run as->run configurations, click on classpath and add your jdbc jar in Add external jars option
您还必须将 jdbc jar 添加到您的服务器类路径。如果是 tomcat,右键单击您的项目-> 运行方式-> 运行配置,单击类路径并在添加外部 jar 选项中添加您的 jdbc jar
回答by Steer360
add ojdbc-6.jar to your lib directory of tomcat installation. Maven will downlowd this jar for you in .m2 directory, but you need to have this jar in tomcat lib as well.
将 ojdbc-6.jar 添加到 tomcat 安装的 lib 目录中。Maven 会在 .m2 目录中为你下载这个 jar,但是你也需要在 tomcat lib 中有这个 jar。