package oracle does not exist

below is my CLASSPATH in System variable

.;C:\PROGRA~1\IBM\SQLLIB\java\db2java.zip;

C:\PROGRA~1\IBM\SQLLIB\java\db2jcc.jar;C:\PROGRA~1\IBM\SQLLIB\java\sqlj.zip;C:\PROGRA~1\IBM\SQLLIB\java\db2jcc_license_cisuz.jar;C:\PROGRA~1\IBM\SQLLIB\java\db2jcc_license_cu.jar;

C:\PROGRA~1\IBM\SQLLIB\bin;

C:\PROGRA~1\IBM\SQLLIB\java\common.jar;

C:\Program Files\Oracle\ora92\jdbc;

C:\Sun\AppServer\jdk\bin

below is my PATH in SYSTEM variable

%SystemRoot%\system32;

%SystemRoot%;

%SystemRoot%\System32\Wbem;

C:\MLTOOLS\;C:\SERVICES\TOOLS\;

C:\Program Files\Oracle\ora92\bin;

C:\Program Files\Oracle\jre\1.3.1\bin\;

C:\Program Files\Oracle\jre\1.1.8\bin;

C:\CA\USD\BIN;

C:\Program Files\Oracle\ora92\NET80\BIN;

C:\Program Files\Attachmate\E!E2K\;

C:\PROGRA~1\IBM\SQLLIB\BIN;

C:\PROGRA~1\IBM\SQLLIB\FUNCTION;

C:\PROGRA~1\IBM\SQLLIB\SAMPLES\REPL;

C:\Sun\AppServer\jdk\bin;

C:\Program Files\Oracle\ora92\jdbc;

i am getting an error in my code as

:\Sun\AppServer\jdk\bin\TestDB.java:3: package oracle.jdbc.driver does not exist

import oracle.jdbc.driver.*;

^

C:\Sun\AppServer\jdk\bin\TestDB.java:15: package oracle.jdbc.driver does not exist

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

[1367 byte] By [anaik100a] at [2007-10-2 13:23:40]
# 1

Because your system CLASSPATH is totally ignored. You shouldn't even have one. javac and java ignore it; IDEs like Eclipse ignore it; app servers like Tomcat and WebLogic ignore it. It's useless.

Where is the ojdbc14.jar file? That's where oracle.jdbc.driver.OracleDriver class is. Add the path to that JAR to your CLASSPATH using the -classpath option when you run java.exe.

%

duffymoa at 2007-7-13 11:01:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

i tried to do the following but got the below error

C:\Sun\AppServer\jdk\bin>java -classpath C:/Program Files/Oracle/ora92/jdbc/lib/

ojdbc14.jar

Exception in thread "main" java.lang.NoClassDefFoundError: Files/Oracle/ora92/jd

bc/lib/ojdbc14/jar

anaik100a at 2007-7-13 11:01:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
The exception suggests that you also have a code problem, something is apparently looking for a class named: " Files/Oracle/ora92/jdbc/lib/ojdbc14/jar"
StuDerbya at 2007-7-13 11:01:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
is it because i have a space between "Program Files"..i am just trying to add this path to my so that my JAva CODe can work..i directly went in to System variables setting and added over there, the path of this jar file but it does not help me..
anaik100a at 2007-7-13 11:01:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
I was refering to a problem in your Java code; the exception is printing the class that is beeing looked for, and there is no such class. I'd guess you have mis-programmed a call to Class.forName() in your java code.
StuDerbya at 2007-7-13 11:01:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

Here is my code where i am getting this error..i am not sure if this error is because of soemthign is wrong in this code..

If that is the case it should have atleast first recognized that my import oracle library exists..

import java.io.*;

import java.sql.*;

import oracle.jdbc.driver.*;

public class TestDB

{

public Connection opendb()

{

Connection conn;

// Load the Oracle JDBC driver

try

{

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

conn = DriverManager.getConnection(

"jdbc:oracle:mat:@clrs.mmmm.dt.com:1527:oooooo",

"test",

"test");

}

catch (SQLException ex)

{

return null;

}

return conn;

}

public boolean closedb(Connection connobj)

{

try

{

connobj.close();

}

catch (SQLException ex)

{

return true;

}

return true;

}

public static void main(String[] args)

{

TestDB TestDBObj = new TestDB();

Connection conn;

if ((conn = TestDBObj.opendb()) == null)

{

System.out.println("open db error\n");

return;

}

// Create a statement

Statement stmt = conn.createStatement();

String output,intable;

String sqlstr = "select distinct optvolumename_nm, doctype_id from clradmin;";

//System.out.println(sqlstr);

ResultSet rset = stmt.executeQuery(sqlstr);

while (rset.next())

{

output = rset.getString(1);

}

System.out.println(output);

rset.close();

stmt.close();

TestDBObj.closedb(conn);

}

}

anaik100a at 2007-7-13 11:01:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
Yes, it's because there's a space in "Program Files". You shouldn't put anything there. If you must, use the DOS equivalent: PROGRA~1.Java isn't look at your PATH or CLASSPATH or anything else.%
duffymoa at 2007-7-13 11:01:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8

This code is wrong. Where did you get that URL to connect to the database? That's not right.

You return null if an exception is caught? You don't print out the stack trace? Bad idea.

What is the name of the JAR you got from Oracle? Is it ojdbc14.jar? (It should be.) Whatever it is, put that JAR in the same directory where you have TestDB.java. Don't think about "installing" it anywhere.

Compile your class like this:

javac TestDB.java

If you don't have compile errors, this will write a TestDB.class file in the same directory where TestDB.java lives.

If ojdbc14.jar is in the same directory as TestDB.class, run it like this:

java -classpath .;ojdbc14.jar TestDB

Note the "dot" as the first entry after -classpath. That tells the class loader to look in the current directory and ojdbc14.jar to find the classes it needs.

The URL should look like this:

jdbc:oracle:thin:@hostname:1521:database

Change the hostname and database to match your situation.

%

duffymoa at 2007-7-13 11:01:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9

Thank you very much for the help duffymo..

1. Can i not set the ojdbc14.jar fiel permanently in the CLASS path

2. jdbc:oracle:thin:@hostname:1521:database

this gives me OpenDB error..

but if i use

jdbc:oracle:thin:@hostname:1527:database

my query is getting executed

anaik100a at 2007-7-13 11:01:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 10

> Thank you very much for the help duffymo..

>

> 1. Can i not set the ojdbc14.jar fiel permanently

You can, but you've already learned that Java ignores it. Why do you persist?

> ly in the CLASS path

>2. jdbc:oracle:thin:@hostname:1521:database

>this gives me OpenDB error..

Then you don't have the thin JDBC driver. Which one do you have?

> but if i use

> jdbc:oracle:thin:@hostname:1527:database

> my query is getting executed

OK, this tells me that someone installed your Oracle listener to use port 1527, which is not the default port. 1521 is the default. You did the right thing by using the one that you were given.

Since you're getting your query executed now, all is well.

%

duffymoa at 2007-7-13 11:01:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...