This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Error  connecting to database from executable JAR file. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Error  connecting to database from executable JAR file." Watch "Error  connecting to database from executable JAR file." New topic
Author

Error connecting to database from executable JAR file.

Vivek Chaitanya
Ranch Hand

Joined: Oct 19, 2007
Posts: 35
Hi All

I created a Swing application which uses ojdbc14.jar for connecting to Oracle 9i database.

I can successfully run the application from command line using javac and also from IDE(MyEclipse).

However I am facing issue when I create executable JAR file for my application. I am not able to connect to Database from JAR even after including ojdbc14.jar in CLASSPATH.

Can someone provide resolution for this issue.

Thank you,
Chaitanya
Hendy Setyo Mulyo
Ranch Hand

Joined: Dec 01, 2004
Posts: 219

How you run the Jar file, by clicking the jar file or using java -jar ... ?


Hendy Setyo Mulyo
SCJP 1.4 (95%), SCWCD 1.4 (94%)
Vivek Chaitanya
Ranch Hand

Joined: Oct 19, 2007
Posts: 35
Hi Hendy

I run by double clicking it.

Thank you,
Chaitanya
Vivek Chaitanya
Ranch Hand

Joined: Oct 19, 2007
Posts: 35
Hi All

Someone please respond.

I need the resolution to this issue badly for my personal project.

Thank you,
Chaitanya
Wayan Saryada
Ranch Hand

Joined: Feb 05, 2004
Posts: 104

What is the actual error message did you get when running your application? Beside configuring a JDBC driver on the classpath have you tried to put a Class-Path entries in your Jar's manifest file?


Website: Learn Java by Examples
Vivek Chaitanya
Ranch Hand

Joined: Oct 19, 2007
Posts: 35
Nope...I didnt mention Class-Path in my manifest.txt
Vivek Chaitanya
Ranch Hand

Joined: Oct 19, 2007
Posts: 35
What are ways I can mention Class-Path

I think( because I havent yet tried)

Class-Path: C:\oracle\ora92\ojdbc14.jar ( I mean absolute path. Thsi may creat issue if I ship my JAR to another machine where the path of ojdbc14.jar is different.)

What if I have to put ojdbc14.jar in my package structure.Can i give the path starting from com.domainName.projectName.packageName. something liek this?
Vivek Chaitanya
Ranch Hand

Joined: Oct 19, 2007
Posts: 35
What are ways I can mention Class-Path

I think( because I havent yet tried)

Class-Path: C:\oracle\ora92\ojdbc14.jar ( I mean absolute path. Thsi may creat issue if I ship my JAR to another machine where the path of ojdbc14.jar is different.)

What if I have to put ojdbc14.jar in my package structure.Can i give the relative path starting from com.domainName.projectName.packageName. something liek this?
Wayan Saryada
Ranch Hand

Joined: Feb 05, 2004
Posts: 104

You can put the JDBC jar file in the same location with your application jar and in the manifest file it will be Class-Path: ojdcb14.jar.
Vivek Chaitanya
Ranch Hand

Joined: Oct 19, 2007
Posts: 35
Thank you Wayan.

I will try this and I think it will work.

I missed out Class-Path in my manifest.

Thank you once again.

Regards
Chaitanya
Vivek Chaitanya
Ranch Hand

Joined: Oct 19, 2007
Posts: 35
By specifying Class-Path in manifest.txt, I can make my executable JAR file work. But I have some issues with this way of making it work.

1. I have to keep ojdbc14.jar file in the same directory as that of my JAR file.

2.My JAR file size is increasing enormously as it also includes classes from ojdbc14.jar

I dont want above two things to happen and I also want to make use of CLASSPATH environment variable. i.e. I want to include ojdbc14.jar in my CLASSPATH and I need to mention that somehow( I dont know how!) in my manifest.txt. Is there any way of doing this?

I tried giving Class-Path: C:\oracle\ora92\ojdbc14.jar ( I mean, absolute path of ojdbc14.jar) in manifest.txt But it is not working this way. I am getting JVM Launch Error stating that "main class not found".

Please let me know how to achieve what I want.

Thank you,
Chaitanya
 
wood burning stoves
 
subject: Error connecting to database from executable JAR file.
 
Similar Threads
about jar ???
creating an executable jar file
accessing ojdbc14.jar from a servlet?
connecting Oracle on linux to windows
ORACLE DRIVER