tags:

views:

2179

answers:

3

Hi all,

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:

I have ojdbc6.jar,orai18n.jar, and class12.jar I set:

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:

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

A: 

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.

You will need the directories with dlls on your PATH.

djna
Could you guide me to configure this problem. Thank
Sopolin
+2  A: 

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.

You can obtain the JDBC drivers for Oracle from the JDBC/UCP page on the Oracle Technology Network.

Additionally, the classes12.jar file is not required, if you already have ojdbcX.jar in the CLASSPATH.

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.

Vineet Reynolds
Could you guide me to configure this problem. Thank
Sopolin
+1  A: 

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.

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.

duffymo
I understand what you tell me but I want guide me to configure it. Because I don't any experience about this. Thanks
Sopolin