This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to open .jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to open .jar file" Watch "How to open .jar file" New topic
Author

How to open .jar file

Suzana Shah
Greenhorn

Joined: Jan 07, 2002
Posts: 12
Hi,
I downloaded the JDBC driver from mysql.com
mm.mysql-2.0.4-bin.jar
and now what, i have installed tomcat and i want to link it to Mysql. I m doing a project on JSP and i need to get values from the database. I have downloaded the driver but now i dont know how to open it, and what to do next with it?
Confused...can anyone help?
Thanks,
Suzana Shah
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The (easiest) answer to your question is that a jar file is actually a zip file that has a jar extension. Rename the file to *.zip then open it in WinZip.
The correct answer, however, is that you don't open the jar. A jar is a "Java Archive", to use it you either put it on your classpath or in the [java home]/lib directory, then you should automatically be able to load the drivers.
If you are doing it within Tomcat or other app servers it sometimes gets a little more complicated. (not too difficult, just behaves differently)
Hope this helps you out, drop a line if you need more
Dave.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Whoops, didn't see where you refered to Tomcat. You have two options here: make the drivers accessible to all web-apps in Tomcat (easier but not generally recommended) or only make it available to a specific web-app.
To make it available to all web-apps, place the jar in the [ TOMCAT_HOME ]/lib directory, otherwise put it in the web-apps/[context]/web-inf/lib directory.
There are some differences between Tomcat 3.* and 4.* so you might need to experiment a bit.
Dave.
(again)
Suzana Shah
Greenhorn

Joined: Jan 07, 2002
Posts: 12
Hi Dave
Thank you, but what do u mean i can do it two ways, you said that i could either have driver available to all web-apps or to specific one,
well what does this mean, and which way is better to use and why. Sorry, its just all so confusing...i did it the way u suggested which is i copied it into the web-apps/[context]/web-inf/lib directory. What i did is copied the driver and pasted it into that directory..is that how i m suppose to do it?
Helppppppp....
Suzee
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

When you create a web ap on an Application Server, the server is able to host multiple "applications" at the same time. So that you can maintain some measure of separation between these applications. Otherwise you could have problems like applications accidentally tripping over each other or applications that require different versions of some API.
If you are only running a single app and it is just a test (or you always use the same database etc etc), dropping the drivers into either directory should be fine, as long as you understand the reasoning for both.
Is this a bit better?
Dave.
Suzana Shah
Greenhorn

Joined: Jan 07, 2002
Posts: 12
Thanks Dave,
This makes it more clearer, so in my case, i m just trying to create a webpage using JSP, linking it a a simple MySql database where there wont be more then 5 tables, i would be able to use either.....is that correct..just confirming
Another query i had was, say i copied the mm.mysql-2.0.4-bin.jar file into the directory as u mentioned.
But other then that do i also have to set a classpath in the autoexe.bat file?
If i do then say if i placed the .jar file in this directory:
C:\jakarta-tomcat-3.3\webapps\admin\WEB-INF\lib
then how would i actually set the classpath...do i sound like i dont have a clue of what i m saying....well i guess i am confused.....Thank you again Dave...for the help so far....
Need hellppppp again
Suzi
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You don't need to set the classpath for the tomcat server, it manages finding and loading classes itself.
It all comes down to the concept of ClassLoaders. (see java.lang.ClassLoader and the Tomcat documentation).
A ClassLoader loads classes (nothing difficult so far). You can create a heirarchy of ClassLoaders to achieve a number of effects, and this is how the manage the "lots of applications in the same VM with differnt classes"
I need to go look it up again, but I think the default directories it load from is defined by the startup scripts and the server properties.
Dave.
 
jQuery in Action, 2nd edition
 
subject: How to open .jar file
 
Similar Threads
Uploading a text file to a blob in MySql, then downloading that file to local file system
Connecting a Java app. to a MySql DB
how to install tomcat 5.5.28
DSN connection
Location of Driver Class in JAVA.