JDBC 瘦 Oracle 11g
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1321253/
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 Thin Oracle 11g
提问by Sopolin
I am using oracle 11g. I write code to connect oracle database with java 1.6, but I can't connect to it. When configure the guide line to below:
我正在使用 oracle 11g。我写了用java 1.6连接oracle数据库的代码,但是连接不上。将指南线配置为以下时:
I have ojdbc6.jar
,orai18n.jar
, and class12.jar
I set:
我有ojdbc6.jar
, orai18n.jar
, 并且class12.jar
我设置了:
Class_Path:
类_路径:
%ORACLE_HOME%\jlib\orai18n.jar;r;%Oracle_home%\jdbc\ojdbc6.jar
After that I run sample java code connect to oracle database, but I met this error below:
之后,我运行示例 java 代码连接到 oracle 数据库,但我遇到了以下错误:
C:\Program Files\Java\jdk1.6.0_11\bin>javac c:\JDBCVersion.java
c:\JDBCVersion.java:2: package oracle.jdbc does not exist
import oracle.jdbc.*;
^
c:\JDBCVersion.java:3: package oracle.jdbc.pool does not exist
import oracle.jdbc.pool.OracleDataSource;
^
c:\JDBCVersion.java:8: cannot find symbol
symbol : class OracleDataSource
location: class JDBCVersion
OracleDataSource ods = new OracleDataSource();
^
c:\JDBCVersion.java:8: cannot find symbol
symbol : class OracleDataSource
location: class JDBCVersion
OracleDataSource ods = new OracleDataSource();
^
4 errors
Could anyone help me to settle this problem?
谁能帮我解决这个问题?
Thanks, Sopolin
谢谢,索波林
采纳答案by djna
I'm not sure what you meant here
我不确定你在这里的意思
Class_Path: %ORACLE_HOME%\jlib\orai18n.jar;%ORACLE_HOME%\oui\jlib\classes12.jar
Path: %Oracle_home%\jdbc\ojdbc6.jar
All the jars should be on the Class_path.
所有的罐子都应该在 Class_path 上。
You will need the directories with dlls on your PATH.
您将需要 PATH 中包含 dll 的目录。
回答by Vineet Reynolds
In order to use the Oracle JDBC driver, you must have the ojdbc6.jar or an equivalent on the CLASSPATH. There is no requirement for any of these JARs to be in the operating system PATH variable.
为了使用 Oracle JDBC 驱动程序,您必须在 CLASSPATH 上有 ojdbc6.jar 或等效文件。这些 JAR 中的任何一个都不需要位于操作系统 PATH 变量中。
You can obtain the JDBC drivers for Oracle from the JDBC/UCP page on the Oracle Technology Network.
您可以从Oracle 技术网上的JDBC/UCP 页面获取 Oracle 的 JDBC 驱动程序。
Additionally, the classes12.jar file is not required, if you already have ojdbcX.jar in the CLASSPATH.
此外,如果 CLASSPATH 中已有 ojdbcX.jar,则不需要 classes12.jar 文件。
Briefly stated, if you are using the Oracle Thin Driver for JDBC against a 11g database, you'll need ojdbc5.jar/ojdbc6.jar and orai18.jar in the CLASSPATH. You'll need additional files for the OCI driver.
简而言之,如果您针对 11g 数据库使用 Oracle Thin Driver for JDBC,您将需要 CLASSPATH 中的 ojdbc5.jar/ojdbc6.jar 和 orai18.jar。您将需要 OCI 驱动程序的其他文件。
回答by duffymo
I wonder if your problem is a mix of JDBC driver JARs. I don't know where you got yours, but you should not have both classes12.jar and ojdbc6.jar. The first one is an older version for JDK 1.2; you should remove it. If you're compiling against JDK 6, use ojdbc6.jar.
我想知道您的问题是否是 JDBC 驱动程序 JAR 的混合。我不知道你从哪里得到的,但你不应该同时拥有 classes12.jar 和 ojdbc6.jar。第一个是 JDK 1.2 的旧版本;你应该删除它。如果您针对 JDK 6 进行编译,请使用 ojdbc6.jar。
I'd also advise that you use the java.sql interfaces and not Oracle specific classes for your static types to keep your code generic. This is only a sample, but you'll want to keep that in mind for your real applications.
我还建议您对静态类型使用 java.sql 接口而不是 Oracle 特定类,以保持代码通用。这只是一个示例,但您需要在实际应用程序中牢记这一点。