Modifying the Java CLASSPATH
The CLASSPATH environment variable contains a list of directories where the Java runtime looks for library class files. For your Java client code to access Vertica, you must add to the CLASSPATH the directory containing the Vertica JDBC .jar
.
Using symbolic links for the CLASSPATH
You can optionally add to the CLASSPATH a symbolic link vertica-jdbc-x.x.x.jar
(where x.x.x is a version number) that points to the JDBC library .jar
file, rather than the .jar
file itself.
Using the symbolic link ensures that any updates to the JDBC library .jar
file (which will use a different filename) will not invalidate your CLASSPATH setting, since the symbolic link's filename will remain the same. You just need to update the symbolic link to point at the new .jar
file.
Linux and OS X
The following examples use a POSIX-compliant shell.
To set the CLASSPATH for the current session:
$ export CLASSPATH=$CLASSPATH:/opt/vertica/java/lib/vertica-jdbc-x.x.x.jar
To set the CLASSPATH for every session, add the following to your start-up file (such as ~/.profile
or /etc/profile
:
$ export CLASSPATH=$CLASSPATH:/opt/vertica/java/lib/vertica-jdbc-x.x.x.jar
Windows
Provide the class paths to the .jar
, .zip
, or .class
files.
C:> SET CLASSPATH=classpath1;classpath2...
For example:
C:> SET CLASSPATH=C:\java\MyClasses\vertica-jdbc-x.x.x.jar
As with the Linux/UNIX settings, this setting only lasts for the current session. To set the CLASSPATH permanently, set an environment variable:
-
On the Windows Control Panel, click System.
-
Click Advanced or Advanced Systems Settings.
-
Click Environment Variables.
-
Under User variables, click New.
-
In the Variable name box, type
CLASSPATH
. -
In the Variable value box, type the path to the Vertica JDBC
.jar
file on your system (for example,C:\Program Files (x86)\Vertica\JDBC\vertica-jdbc-x.x.x.jar
)
Specifying the library directory in the Java command
Another, OS-agnostic way to tell the Java runtime where to find the Vertica JDBC driver is to explicitly add the directory containing the .jar
file to the Java command line using either the -cp
or -classpath
argument. For example, you can start your client application with:
java -classpath /opt/vertica/java/lib/vertica-jdbc-x.x.x.jar myapplication.class
Your Java IDE may also let you add directories to your CLASSPATH, or let you import the Vertica JDBC driver into your project. See your IDE documentation for details.