Solved

Oracle JDBC problem

Posted on 2008-10-05
15
435 Views
Last Modified: 2013-11-23
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
0
Comment
Question by:mawingho
  • 5
  • 5
  • 3
  • +1
15 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 300 total points
ID: 22647122
Here is a discussion on the same issue:

http://forums.oracle.com/forums/thread.jspa?threadID=426544 

My thoughts/questions would be:
+Have you rebooted since adding oracle JAR to your classpath?
+Do you have oracle JAR included in the build path of your project within IDE you are using to code?
+Do you have import statement that is not showing in code snippet, as the correct class name for the oracle driver is oracle.jdbc.OracleDriver()?

HTH
/kev
0
 
LVL 2

Assisted Solution

by:priya_patil
priya_patil earned 150 total points
ID: 22647632
where is the OracleDriver class in
DriverManager.registerDriver(new OracleDriver())

you can directly write
DriverManager.registerDriver("oracle.jdbc.driver.OracleDriver");
0
 

Author Comment

by:mawingho
ID: 22647647
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>
0
 
LVL 2

Assisted Solution

by:priya_patil
priya_patil earned 150 total points
ID: 22647791
write to register driver

DriverManager.registerDriver((java.sql.Driver)(Class.forName("oracle.jdbc.driver.OracleD
river").newInstance()));
0
 

Author Comment

by:mawingho
ID: 22647811
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>
0
 
LVL 2

Assisted Solution

by:priya_patil
priya_patil earned 150 total points
ID: 22647874
yes this is because the jar file is not there in class path
add it to
environment variables -> system variable -> class path -> path to oracle driver jar file (must be ojdbc.. .jar)
close command prompt
open a new command prompt after setting value from environment variables (my computer -> properties -> advanced )
compile it and run it
0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 300 total points
ID: 22649057
Please follow-up on my comment above - http:#22647122.
Please take a look at the link and answer three questions and post back if that doesn't resolve issue.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 50 total points
ID: 22656572
Once you set the classpath on the system property, You need to create a new command window, to conform the changes
has taken effect, you should type:

echo %CLASSPATH%
0
 

Author Comment

by:mawingho
ID: 22665404
C:\Documents and Settings\msp064646>echo %CLASSPATH%
%CLASSPATH%
0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 300 total points
ID: 22665494
lol. that is funny! unless that is seriously what you got back, then that means you have something wrong as you should get back your classpath like you see in environment variables.

echo %PATH%
echo %CLASSPATH%

Responses should not be %PATH% and %CLASSPATH%, should be string of file paths separated by semi-colons (;).
0
 

Author Comment

by:mawingho
ID: 22665715
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>

0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 300 total points
ID: 22665740
Try :

javac -cp .;C:\ojdbc14.jar Oracle.java
0
 

Author Comment

by:mawingho
ID: 22665754
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

0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 300 total points
ID: 22665796
Are you getting an error now?  I would test with your original code.
import java.sql.*;

 

public class Test {

 

	//Connection conn = null;

 

	public static void main(String [] args){

		try {

			DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

		} catch (Exception e) { 

			System.out.println("ERROR : " + e);

			e.printStackTrace(System.out);

		}

	}

}

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now