Database Reference
In-Depth Information
Let's imagine that you have installed the JDK in this directory:
C:\Program Files\java\jdk1.6
Imagine you also placed the Oracle JDBC file at this location:
C:\Program Files\java\ojdbc6.jar
You do not need to set the environment variables, but the difference in Java command line syntax is
significant. Following are two examples of running the Java Oracle application MyApp from the command
prompt. In the first command, we have set and rely on our environment settings. The second would be
required if we do not have our environment set.
java MyApp
C:/Program Files/java/jdk1.6/bin/java -cp “.;C:\Program Files\java\ojdbc6.jar” MyApp
You can readily see how much easier it is to run from the command line if your environment is
properly configured. If you're running Windows XP or later, then right click on My Computer on the
desktop and choose Properties, or right-click on Computer in your Start menu and choose Properties.
Select the Advanced tab or button and click on Environment Variables. At the top, create two (new) user
variables (or modify existing) with the settings listed in Table 3-1.
Table 3-1. Environment Variables
Variable Name
Variable Value
PATH
C:\Program Files\java\jdk1.6\bin;
CLASSPATH
.;C:\Program Files\java\ojdbc6.jar;%CLASSPATH%
The PATH user environment variable will be automatically appended to the System PATH, and will
tell Windows how to find the Java compiler (javac.exe) and Java runtime (java.exe) executables.
Beware that even after setting your path, there might be other java.exe executables earlier in the
PATH. Assure that the versions of javac.exe and java.exe are both 1.5 or later. Open the command
prompt from your Start menu and check the results of these commands:
javac -version
java -version
In the CLASSPATH user environment variable, we are saying several things. First of all the dot (.) tells
Java to find classes in the current directory. Trust me, you do not want to be caught asking Java, “Why
can't you find the file—it's right here?” The second thing we point to is the Oracle code in the ojdbc6.jar
file—we want Java to automatically find that code. And the third thing we are saying is that we want
whatever system environment CLASSPATH already exists (%CLASSPATH%) appended to our CLASSPATH .
Just to elaborate a bit, the CLASSPATH is a list of places that we want Java to look for compiled classes.
These places are really just starting points, and can include directories (like our “dot” current directory)
and archive files (JAR files or ZIP files). When we compile or run our own code and need to use existing
code, we can find it along the CLASSPATH . Java opens archive files and looks at the included directories
and files to see if what we need is there. If I refer to oracle.sql.ARRAY in my code, Java will eventually
open the ojdbc6.jar file from the CLASSPATH and find the oracle directory. It will then continue to find the
sql directory, and from there, the ARRAY.class file.
 
Search WWH ::




Custom Search