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);
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