如何为 Oracle JDBC 瘦驱动程序设置环境变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13572714/
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-09-19 01:17:24  来源:igfitidea点击:

How to set Environment variable for Oracle JDBC thin driver

javadatabaseoraclejdbc

提问by

After installing Oracle 11g R2 on my system, I set the environment variable as following:

在我的系统上安装 Oracle 11g R2 后,我将环境变量设置如下:

variable Name :CLASSPATH 
variable Value :E:\app\JamesPJ\product.2.0\dbhome_1\jdbc\lib\ojdbc6.jar
Variable name : ORACLE_HOME
varaible value :E:\app\JamesPJ\product.2.0\dbhome_1\jdbc\lib\ojdbc6.jar

When I run the program using testpad and in command prompt the error comes as follows :

当我使用 testpad 和命令提示符运行程序时,错误如下:

Error: Could not find or load main class test

错误:无法找到或加载主类测试

How is this caused and how can I solve it?

这是怎么引起的,我该如何解决?

采纳答案by BalusC

Java looks in the classpath for all classes. You've however set the classpath to a single fixed JAR file which is the JDBC driver itself. This JAR file surely doesn't contain your own test.classfile. Provided that your test.classis available in the current working directory, you should have added the current working directory .to the classpath.

Java 在类路径中查找所有类。但是,您已将类路径设置为单个固定 JAR 文件,即 JDBC 驱动程序本身。这个 JAR 文件肯定不包含您自己的test.class文件。如果您test.class在当前工作目录中可用,您应该已将当前工作目录添加.到类路径中。

.;E:\app\JamesPJ\product.2.0\dbhome_1\jdbc\lib\ojdbc6.jar

Note that the paths in the classpath are semi colon separated in Windows and colon separated in *nix.

请注意,类路径中的路径在 Windows 中以分号分隔,在 *nix 中以冒号分隔。

Alternatively, you could also just control the classpath during execution by the -cpargument. This way the environment variable will be ignored altogether.

或者,您也可以在执行期间通过-cp参数控制类路径。这样环境变量将被完全忽略。

java -cp .;E:\app\JamesPJ\product.2.0\dbhome_1\jdbc\lib\ojdbc6.jar test

To avoid the tedious work of re-entering the whole command everytime, put it in a .bator .cmdfile and execute it instead.

为了避免每次重新输入整个命令的繁琐工作,将其放在一个.bat.cmd文件中并执行它。