wood burning stoves 2.0*
The moose likes JDBC and the fly likes Set classpath problem (Oracle9.01) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Set classpath problem (Oracle9.01)" Watch "Set classpath problem (Oracle9.01)" New topic
Author

Set classpath problem (Oracle9.01)

nan sh
Ranch Hand

Joined: Jan 05, 2001
Posts: 167
I am using jdk1.4.
I have copied ojdbc14.jar to C:\j2sdk\jre\lib\ext and I can compile Employee.java successfully.
But when I run Employee, got error as
'Exception in thread "main" java.lang.NoClassDefFoundError: oracle/jdbc/driver/OracleDriver
at Employee.main(Employee.java:18)'
So I run
jar -xvf ojdbc14.jar,
to extract oracle folder inside ojdbc14.jar and copy it to my current working place then I can run Employee, if I delete the oracle folder (which is extracted from ojdbc14.jar) from the current working folder, it won't work again!
I couldn't find out what is wrong, anyone has any idea?
The following is Employee.java
/*
* This sample shows how to list all the names from the EMP table
*
* It uses the JDBC THIN driver. See the same program in the
* oci8 samples directory to see how to use the other drivers.
*/
// You need to import the java.sql package to use JDBC
import java.sql.*;
import oracle.jdbc.*;
class Employee
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
//DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as <host>:<port>:<sid>. The example uses the short cut syntax.
//String url = "jdbc racle:thin:@dog:1521:nan";
//String userName = "nan";
//String password = "nan";
String url = "jdbc racle:thin:@dog:1521 EV";
String userName = "scott";
String password = "tiger";
if (args.length > 0) url = args[0];
if (args.length > 1) userName = args[1];
if (args.length > 2) password = args[2];
Connection conn =
DriverManager.getConnection (url, userName, password);
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP");
// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}
[ April 05, 2003: Message edited by: nan sh ]

Have you tried this Mock Exam Testing Engine yet?<br /><a href="http://www.mycgiserver.com/~nan111/index.html" target="_blank" rel="nofollow">www.mycgiserver.com/~nan111/index.html</a>
Lilac Ezer
Greenhorn

Joined: Apr 08, 2003
Posts: 8
Did you try to add ojdbc14.jar explicity to the end of your CLASSPATH environment variable?
nan sh
Ranch Hand

Joined: Jan 05, 2001
Posts: 167
"Did you try to add ojdbc14.jar explicity to the end of your CLASSPATH environment variable? "
Yes. It looks like javac can recognize *.jar inside JAVA_HOME\jer\lib\ext, but java cannot, is this the java's behave?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Is it possible that you're running Windows and Microsoft's java.exe is running instead of Sun's java.exe?
What's the result of running java -version from a working directory that is not your [JRE_HOME]/bin folder?
If Microsoft's java.exe is interfering, then you can usually correct this problem by deleting it, renaming it, or specifying the location of Sun's java.exe first in the PATH setting.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set classpath problem (Oracle9.01)
 
Similar Threads
Servlet and Java class
Oracle 9i thru WSAD5.0 Problem!!!!!
excepttion in thread "main" java.sql.SQLException: Io exception: The Network Adapter
Oracle9i Connectivity thru wsad5.o
package oracle.jdbc.driver does not exist