9951 explained code solutions for 126 technologies

amazon-redshiftHow can I integrate Amazon Redshift with Hadoop?

Integrating Amazon Redshift with Hadoop requires the use of the Amazon Redshift JDBC driver. This driver allows you to connect to Redshift clusters from Java applications running on Hadoop clusters.

The following example code demonstrates how to connect to a Redshift cluster from a Java application running on Hadoop:

import java.sql.Connection;
import java.sql.DriverManager;

public class RedshiftConnection {
  public static void main(String[] args) {
    try {
      // Load the Redshift JDBC Driver

      // Create a connection to the Redshift cluster
      Connection con = DriverManager.getConnection(

      System.out.println("Connected to Redshift.");
    } catch (Exception e) {
      System.err.println("Error connecting to Redshift.");

Output example

Connected to Redshift.

The code consists of the following parts:

  1. Class.forName("com.amazon.redshift.jdbc.Driver") - Loads the Redshift JDBC driver.
  2. DriverManager.getConnection() - Establishes a connection to the Redshift cluster. This method requires the cluster endpoint, username and password as parameters.
  3. System.out.println("Connected to Redshift.") - Prints a message indicating that the connection was successful.

For more information, see the Amazon Redshift JDBC Driver Documentation.

Edit this code on GitHub