Link to home
Start Free TrialLog in
Avatar of Billy Ma
Billy MaFlag for Hong Kong

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.registerDriver(new OracleDriver());
                                                         ^
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);
		}
	}
}

Open in new window

path.JPG
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Billy Ma

ASKER

still doesn't work...

C:\Documents and Settings\msp064646\My Documents\Development>javac *.java
Test.java:9: registerDriver(java.sql.Driver) in java.sql.DriverManager cannot be
 applied to (java.lang.String)
                        DriverManager.registerDriver("oracle.jdbc.driver.OracleD
river");
                                     ^
1 error

C:\Documents and Settings\msp064646\My Documents\Development>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>javac *.java

C:\Documents and Settings\msp064646\My Documents\Development>java Test
ERROR : java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at Test.main(Test.java:9)

C:\Documents and Settings\msp064646\My Documents\Development>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
C:\Documents and Settings\msp064646>echo %CLASSPATH%
%CLASSPATH%
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;E:\Ora920_w2k\bin;e:\orant\bin;C:\Program Files\Oracle
\jre\1.1.8\bin;f:\tools;C:\oracle\BIToolsHome_1\bin;C:\oracle\BIToolsHome_1\jlib;C:\oracle\BIToolsHome_1\jre\1.4.2\bin\client;C:\oracle\BIToolsHome_1\
jre\1.4.2\bin;C:\Program Files\Windows Imaging\;C:\ojdbc14.jar;E:\Ora920_w2k\jdbc\lib\;

C:\Documents and Settings\msp064646>echo %CLASSPATH%
%CLASSPATH%

C:\Documents and Settings\msp064646>

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
my code called Test.java is attached below

C:\Documents and Settings\msp064646\My Documents\Development>javac -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>
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);
		}
		
	}
}

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial