Billy Ma
asked on
Oracle JDBC problem
The oracle server that I'm using is
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
I downloaded the driver for Oracle JDBC from Oracle website, and also set the path as shown in the picture. Then I created a Java file, and COMPILED it, and I got the following error message
Oracle.java:9: cannot find symbol
symbol : class OracleDriver
location: class Oracle
DriverManager.registerDriv er(new OracleDriver());
^
1 error
How to fix it?
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
I downloaded the driver for Oracle JDBC from Oracle website, and also set the path as shown in the picture. Then I created a Java file, and COMPILED it, and I got the following error message
Oracle.java:9: cannot find symbol
symbol : class OracleDriver
location: class Oracle
DriverManager.registerDriv
^
1 error
How to fix it?
import java.sql.*;
public class Oracle{
Connection conn = null;
public static void main(String [] args){
try {
DriverManager.registerDriver(new OracleDriver());
} catch (Exception e) {
System.out.println("ERROR : " + e);
e.printStackTrace(System.out);
}
}
}
path.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
When I execute it, I got the following errors, is it becoz the path or classpath doesn't work?
C:\Documents and Settings\msp064646\My Documents\Development>java c *.java
C:\Documents and Settings\msp064646\My Documents\Development>java Test
ERROR : java.lang.ClassNotFoundExc eption: oracle.jdbc.driver.OracleD river
java.lang.ClassNotFoundExc eption: oracle.jdbc.driver.OracleD river
at java.net.URLClassLoader$1. run(Unknow n Source)
at java.security.AccessContro ller.doPri vileged(Na tive Method)
at java.net.URLClassLoader.fi ndClass(Un known Source)
at java.lang.ClassLoader.load Class(Unkn own Source)
at sun.misc.Launcher$AppClass Loader.loa dClass(Unk nown Source)
at java.lang.ClassLoader.load Class(Unkn own Source)
at java.lang.ClassLoader.load ClassInter nal(Unknow n Source)
at java.lang.Class.forName0(N ative Method)
at java.lang.Class.forName(Un known Source)
at Test.main(Test.java:9)
C:\Documents and Settings\msp064646\My Documents\Development>
C:\Documents and Settings\msp064646\My Documents\Development>java
C:\Documents and Settings\msp064646\My Documents\Development>java
ERROR : java.lang.ClassNotFoundExc
java.lang.ClassNotFoundExc
at java.net.URLClassLoader$1.
at java.security.AccessContro
at java.net.URLClassLoader.fi
at java.lang.ClassLoader.load
at sun.misc.Launcher$AppClass
at java.lang.ClassLoader.load
at java.lang.ClassLoader.load
at java.lang.Class.forName0(N
at java.lang.Class.forName(Un
at Test.main(Test.java:9)
C:\Documents and Settings\msp064646\My Documents\Development>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
C:\Documents and Settings\msp064646>echo %CLASSPATH%
%CLASSPATH%
%CLASSPATH%
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
There is no CLASSPATH in my system variable
C:\Documents and Settings\msp064646>echo %PATH%
.;C:\Program Files\Java\jdk1.6.0_07\bin ;C:\WINDOW S\system32 ;C:\WINDOW S;C:\WINDO WS\System3 2\Wbem;E:\ Ora920_w2k \bin;e:\or ant\bin;C: \Program Files\Oracle
\jre\1.1.8\bin;f:\tools;C: \oracle\BI ToolsHome_ 1\bin;C:\o racle\BITo olsHome_1\ jlib;C:\or acle\BIToo lsHome_1\j re\1.4.2\b in\client; C:\oracle\ BIToolsHom e_1\
jre\1.4.2\bin;C:\Program Files\Windows Imaging\;C:\ojdbc14.jar;E: \Ora920_w2 k\jdbc\lib \;
C:\Documents and Settings\msp064646>echo %CLASSPATH%
%CLASSPATH%
C:\Documents and Settings\msp064646>
C:\Documents and Settings\msp064646>echo %PATH%
.;C:\Program Files\Java\jdk1.6.0_07\bin
\jre\1.1.8\bin;f:\tools;C:
jre\1.4.2\bin;C:\Program Files\Windows Imaging\;C:\ojdbc14.jar;E:
C:\Documents and Settings\msp064646>echo %CLASSPATH%
%CLASSPATH%
C:\Documents and Settings\msp064646>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
my code called Test.java is attached below
C:\Documents and Settings\msp064646\My Documents\Development>java c -cp .;C:\ojdbc14.jar Test.java
C:\Documents and Settings\msp064646\My Documents\Development>java -cp .;C:\ojdbc14.jar Test
C:\Documents and Settings\msp064646\My Documents\Development>
C:\Documents and Settings\msp064646\My Documents\Development>java
C:\Documents and Settings\msp064646\My Documents\Development>java
C:\Documents and Settings\msp064646\My Documents\Development>
Note from modus_operandi, EE Moderator
Connection parameters expunged
import java.sql.*;
public class Test{
/*Connection conn = null;*/
public static void main(String [] args){
try {
//DriverManager.registerDriver((java.sql.Driver)(Class.forName("oracle.jdbc.driver.OracleDriver").newInstance()));
//DriverManager.registerDriver("oracle.jdbc.driver.OracleDriver");
Class.forName("oracle.jdbc.driver.OracleDriver");
//DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
//Connection con = DriverManager.getConnection(<connection parameters>);
} catch (Exception e) {
System.out.println("ERROR : " + e);
e.printStackTrace(System.out);
}
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
C:\Documents and Settings\msp064646\My Documents\Development>java
Test.java:9: registerDriver(java.sql.Dr
applied to (java.lang.String)
DriverManager.registerDriv
river");
^
1 error
C:\Documents and Settings\msp064646\My Documents\Development>