Connecting to Your Database Using JDBC Driver



Here, we will show you how you can use Progress DataDirect JDBC drivers in your Java application to connect to your database. The main objectives of this tutorial are to demonstrate:

  1. Connecting to your data source using JDBC

  2. Running simple SQL queries to fetch data

Read More: JDBC Driver


Prerequisites

We expect you have the following setup before proceeding further with this tutorial.

  1. Have Postgres installed on your machine/server

  2. Have a Salesforce account. In case you don’t have one, register yourself for one

  3. Download and Install Progress DataDirect JDBC drivers for Postgres and Salesforce

If you're interested in connecting to just one data source, then you only need to set up one of these.


Importing Sample Database Into Postgres

  • If you need data for your Postgres, you can download the DVD rental sample database and import it. To import the sample database, create a database in Postgres by running the following command either in psql or pgAdmin.

create database dvdrentals;
  • Now run the following command to import the database from the downloaded database backup.

pg_restore -U -d dvdrentals /path/to/dvdrental.tar


Connecting to Your Data Source

With everything setup for you to connect to database, let’s start the fun by writing code to connect to your data source.

  • Open your favorite IDE and create a new Java project.