User`s guide

PostgreSQL JDBC for Linux
2-153
PostgreSQL JDBC for Linux
This tutorial shows how to set up a data source and connect to your PostgreSQL
database. This tutorial uses the JDBC4 PostgreSQL Driver, Version 8.4 to connect to the
PostgreSQL 9.2 database.
In this section...
“Step 1. Verify the driver installation.” on page 2-153
“Step 2. Add the JDBC driver to the MATLAB static Java class path.” on page 2-153
“Step 3. Set up the data source using Database Explorer.” on page 2-154
“Step 4. Connect using Database Explorer or the command line.” on page 2-156
Step 1. Verify the driver installation.
If the JDBC driver for PostgreSQL is not installed on your computer, find the link on the
Driver Installation page to install the driver. Follow the instructions to download and
install this driver on your computer.
Step 2. Add the JDBC driver to the MATLAB static Java class path.
1
Run the prefdir command in the Command Window. The output is a file path to a
folder on your computer.
2
Close MATLAB if it is running.
3
Navigate to the folder and create a file called javaclasspath.txt in the folder.
4
Open javaclasspath.txt. Add the full path to the database driver JAR file in
javaclasspath.txt. The full path includes the path to the folder where you
downloaded the JAR file from the database provider and the JAR file name. For
example, /home/user/DB_Drivers/postgresql-8.4-702.jdbc4.jar. Save and
close javaclasspath.txt.
5
Restart MATLAB.
Alternatively, you can use javaaddpath to add your JDBC driver to the dynamic Java
class path. For details about static and dynamic class paths, see “Bringing Java Classes
into MATLAB Workspace”.