PostgreSQL ODBC for Linux DSN-Less Connection
This tutorial shows how to verify your driver installation and connect to a PostgreSQL database using a DSN-less connection string at the command line. (DSN is a data source name.) The tutorial uses the JDBC4 PostgreSQL Driver, Version 8.4 to connect to a PostgreSQL 9.2 database on the Linux® platform.
Step 1. Verify the driver installation.
The ODBC driver is typically preinstalled on your computer. For details about the driver installation or troubleshooting the installation, contact your database administrator or refer to your database documentation on ODBC drivers.
Step 2. Connect using the DSN-less connection string and command line.
Connect to the database using the DSN-less connection string with the
odbc
function. For example, this code assumes that you are connecting to the local database server, database nametoystore_doc
, user nameusername
, and passwordpwd
.dsnless = strcat("Driver={PostgreSQL ANSI};Servername=localhost;", ... "Database=toystore_doc;UID=username;PWD=pwd"); conn = odbc(dsnless);
Close the database connection.
close(conn)