-
Error: "package oracle.jdbc does not exist"
Hello,
I'm trying to write a simple Java example that pulls from an Oracle Database, however, I keep getting this error when I try to compile it.
-----------------------------------------------------------------
Test/FirstExample.java [22:1] package oracle.jdbc does not exist
Class.forName(oracle.jdbc.driver.OracleDriver);
^
1 error
Errors compiling FirstExample.
-----------------------------------------------------------------
Here's what my classpath is set to:
CLASSPATH=.;D:\Oracle\ora92\jdbc\lib\ojdbc14.jar;D:\Oracle\ora92\jdbc\lib\ocrs12.zip
Here's what my path is set to:
PATH=D:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program
Files\Oracle\jre\1.1.8\bin;C:\j2sdk1.4.2_04\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\Syst em32\Wbem
Here's what my Java_home is set to:
JAVA_HOME=C:\j2sdk1.4.2_04
Here's what my oracle_home is set to:
ORACLE_HOME=D:\Oracle\ora92
I'm using the 1.4.2 Java SDK and I'm running the Oracle Server on the same box
that I'm developing on (no Oracle client is installed)
Here is my code:
------------------------------------------------------------------------
package Test;
import java.sql.*;
public class FirstExample {
public static void main(String[] args){
//declare Connection and Statement Objects
Connection myConnection = null;
Statement myStatement = null;
try{
//register the Oracle JDBC drivers
Class.forName(oracle.jdbc.driver.OracleDriver);
//create a connection object, and connect to the database as system
//using the oracle JDBC Thin driver
myConnection = DriverManager.getConnection("jdbc:oracle:thin@dev:1521:ORACLASS", "system", "password");
//create a statement object
myStatement = myConnection.createStatement();
ResultSet myResultSet = myStatement.executeQuery("SELECT user, sysdate " +
"FROM dual");
...deleted rest of script
-----------------------------------------------------------------------------
I know that package exists on my computer because I can find it in windows explorer. I also noticed when i tried to use the OracleDataSource class, I pretty
much got the same error. Again, I can find the class in Windows Explorer, so I know it's there. I thought I had the CLASSPATH set right, however, now I have
no clue what's going on. Please help, any help would be
greatly appreciated.
Thanks in advance,
ChrisClass.forName(oracle.jdbc.driver.OracleDriver);
-
See Chapter 18 of Java Developer's Guide and Reference for syntax, that may help.
Last edited by stecal; 06-28-2004 at 09:10 PM.
-
I don't know which Java development tool you are using (I'm using Eclipse) but I can provide you a basic Java-Oracle connection example.
All you'll need is classes12.jar; the file must be imported in your Java project. You can find it in your \\ORAHOME\JDBC\LIB directory.
Then you can do this:
----------------
import java.sql.*;
public class FirstExample {
public static void main(String[] args) {
try {
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc: oracle:thin:@localhost:1521:RESEARCH","scott","tiger");
// jdbc: oracle:thin - JDBC driver
// localhost (it also accepts IP)
// 1521 - port
// RESEARCH - SID
// scott - username
// tiger - password
Statement stmt = conn.createStatement();
// a select query
ResultSet rset = stmt.executeQuery ("SELECT ename FROM emp");
while (rset.next()) {
System.out.println("ENAME = " + rset.getString(1));
}
rset.close();
stmt.close();
conn.close();
} catch (Exception e) {
System.out.println("ERROR : " + e.getMessage());
}
}
}
--------------------
Works for me, the result is
ENAME = SMITH
ENAME = ALLEN
ENAME = WARD
...
...
Samo Decman
I love deadlines. I especially like the whooshing sound they make as they go
flying by. (c)Dilbert
-
Thanks for responding
Thanks for the response...but I thought the classes12.zip was for the java 1.3 version and ojdbc14.jar was for java 1.4.2?
Also, I got it to work in Netbeans by mounting an archive and then pointing to the ojdbc14.jar file, however, how would one compile and run this from the command line if the only way for it to work is to import these files into your project?
Thanks for your help!
Take care,
Chris
-
Yes and no. Classes12.jar work well in Java 1.1 and above environment, but ojdbc14.jar is ONLY for Java 1.4x. But since your default JRE is of version 1.3.1, your code wouldn't run even if you would get it compiled with your Java 1.4.1_03 SDK. That's why I used classes12 in my example.
Furthermore, the interface of both jars is the same, so instead of classes12.jar include ojdbc14.jar in above example. No code modification needed.
So how do you compile and run the program in a "stone age style"?
javac -classpath C:\oracle\ora92\jdbc\lib\ojdbc14.jar FirstExample.java
java -cp .;C:\oracle\ora92\jdbc\lib\ojdbc.jar FirstExample
Why don't you download a Java development tool? Here's my favourite
http://eclipse.cis.sinica.edu.tw/dow...-3.0-win32.zip
It's a nice little tool, free, about 80 Megs with all important features, no installation needed. And you don't need a P4 3.0 with 1GB RAM to run it. It's suitable for beginners, no need to be heavy-duty Java programmer.
I love deadlines. I especially like the whooshing sound they make as they go
flying by. (c)Dilbert
-
package oracle.jdbc does not exist
Hi all,
I also was trying to depoly a simple JSP page with a SQL call to an oracle instance, but I keep getting the "package oracle.jdbc does not exist" or simiar errors.
I used Eclipse IDE and deployed to Tomcat server, which I thought might be the problem, so I downloaded and installed Sun's Glassfish server. The same problem persisted.
I followed instructions/advice and added the file C:\oracle\product\10.2.0\db_1\jdbc\lib\classes12.jar to my build path. Would not work.
Finally, I happened to notice a warning from eclipse:
"Classpath entry C:/oracle/product/10.2.0/db_1/jdbc/lib/classes12.jar will not be exported or published. Runtime ClassNotFoundExceptions may result."
If you see this warning, right mouse it and choose Quick Fix - a dialog offers two quick fixes, the first one will be:
"Mark the associated raw classpath entry as publish/export dependency."
With this option highlighed click Finish - this will remove the warning and resolve this problem.
Once I did that my jsp page worked correctly in either Tomcat or Glassfish. I tried it on several other projects and it also worked.
I hope this was helpful - it worked for me.
JC
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|