Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

application connects to Oracle but executable jar can't

Status
Not open for further replies.

cadoltt

Programmer
Jun 9, 2005
85
CA
Hi everybody!

I need to clarify something. I've created a simple application which connects to an Oracle db and executes a simple Select query. I work with Eclipse and when I run the app from within Eclipse, or I start it from the command prompt window, it goes all right but when I try to run an executable jar, connection fails and I am getting an error message: 'java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver'.

The oracle driver is added to my CLASSPATH variable. Is there anything I have to add to the jar?

Can anyone help?

Thanks,
Alex
 
The driver class is called :

oracle.jdbc.driver.OracleDriver

not :

oracle.jdbc.OracleDriver

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Hi sedj,

Thanks for your response. I changed the class name but it didn't help - now I'm getting this message:
'java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver'

Should it be anything specific in the Manifest file?

Thanks again,
Alex
 
You do have classes12.jar in the CLASSPATH ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
sedj,

I use ojdbc14_g.jar and it is set in the CLASSPATH...

Alex
 
Never used ojdbc14_g.jar - try using classes12.jar, or at least adding it to your CLASSPATH - this is where the class you are missing lives.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
sedj,

Thank you for your help.

I downloaded classes12.zip added it to the CLASSPATH, rebuit the app but still having the same problem with the same error message.

Is it essential that I installed classes12.zip, not classes12.jar?

Alex
 
I've seen odd things happen when you add classes12.zip - rename the file classes12.jar .

If you still have problems, then I can pretty much assure you classes12.jar is not on your CLASSPATH.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
sedj,

I did what you suggested, and checked my CLASSPATH (I actually corrected the file extension in there as well). Doesn't work....


Alex
 
Try this programme in a DOS or Linux console :

Code:
public class TestDriverClass {
  public static void main(String[] args) {
    Class.forName("oracle.jdbc.driver.OracleDriver");
  }
}

Compile it, and then run it like this :

First, set your classpath by hand,

On Linux :
export CLASSPATH=.:/path/to/classes12.jar

or on Win32 :

set CLASSPATH=.;C:\path\to\classes12.jar

and then run it :

java TestDriverClass

What happens ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Diancecht,

Thanks for joining.

I cant compile it it gives me the following error message:

TestDriverClass.java:5: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown Class.forName("oracle.jdbc.driver.OracleDriver");

What's wrong?

Alex
 
Just a try-catch block

Code:
public class TestDriverClass {
  public static void main(String[] args) {
   try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
   } catch (Exception e) {
    e.printstacktrace();
   }
  }
}

Cheers,
Dian
 
Diancecht,

I embraced the code into try/catch block and it compiled.

When I ran it, nothing happened, after a little while it came to the usual system prompt (I work in win 2000).

....Alex
 
If you run a program from an jar, the classpath has to be specified in the manifest:

Class-Path: xyz.jar

The classpath-variable is ignored afaik.

sedj: I thought classes12.jar where introduced for java-1.2, and used oracle10g recently, which introduced a different jar, but it's on a different machine now, so I can't verify the name, but I surely didn't need a 'classes12.jar'.

seeking a job as java-programmer in Berlin:
 
Dian,

yes, I included messages in the try-catch block:

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("all OK");
}
catch (Exception e)
{
System.out.println("Err=" + e);
}

I also tried this

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("all OK");
}
catch(ClassNotFoundException e)
{
System.out.println("Err=" + e);
}


In both cases when it runs, comes the message "all OK".



stefanwagner,

Thank you too for joining the club :)

I included the line into my manifest file. Here it is:

Manifest-Version: 1.0
Main-Class: clsMain
Class-Path: C:\j2sdk1.4.2_03\oracle_driver\classes12.jar


But now I am getting another strange message when I try to run the jar file:

'Could not find the main class. Program will exit'


I looked into the jar, my clsMain (which contains the main function) is in there...

Alex
 
Right - so what this all means then, is that the driver IS FOUND in your manual classpath - and your other programme does not have the classpath defined- so as I said before- its a CLASSPATH issue which you need to resolve.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
sedj,

Here is my entire CLASSPATH var:

C:\Program Files\Java\jre1.5.0_04\lib\ext\QTJava.zip;C:\j2sdk1.4.2_03\oracle_driver\ojdbc14_g.jar;C:\j2sdk1.4.2_03\oracle_driver\classes12.jar;


Anything wrong with it?

Thanks,
Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top