Configuring a JDBC driver version 2.0 connection - Amazon Redshift

Configuring a JDBC driver version 2.0 connection

You can use a JDBC driver version 2.0 connection to connect to your Amazon Redshift cluster from many third-party SQL client tools. To do this, you download a JDBC driver.

To use a JDBC connection, perform the following steps and use the following options.

Configure authentication and SSL for your JDBC connection

Configure the Amazon Redshift JDBC driver to authenticate your connection according to the security requirements of the Amazon Redshift server that you are connecting to.

To authenticate the connection, always provide your Amazon Redshift user name and password. The password is transmitted using a salted MD5 hash of the password. Depending on whether Secure Sockets Layer (SSL) is enabled and required on the server, you might also need to configure the driver to connect through SSL. You might need to use one-way SSL authentication so that the client (the driver itself) verifies the identity of the server.

Configure TCP keepalives for your JDBC connection

By default, the Amazon Redshift JDBC driver is configured to use TCP keepalives to prevent connections from timing out. You can specify when the driver starts sending keepalive packets or disable the feature by setting the relevant properties in the connection URL. For more information about the syntax of the connection URL, see Building the connection URL.

Property Description

TCPKeepAliveMinutes

To specify when the driver sends keepalive packets, set the number of minutes of inactivity before the driver starts sending TCP keepalive packets.

TCPKeepAlive

To disable TCP keepalives, set this property to FALSE.

Configure your JDBC connection with Apache Maven

Apache Maven is a software project management and comprehension tool. The AWS SDK for Java supports Apache Maven projects. For more information, see Using the SDK with Apache Maven in the AWS SDK for Java Developer Guide.

If you use Apache Maven, you can configure and build your projects to use an Amazon Redshift JDBC driver to connect to your Amazon Redshift cluster. To do this, add the JDBC driver as a dependency in your project's pom.xml file. If you use Maven to build your project and want to use a JDBC connection, take the steps in the following section.

Configuring the JDBC driver as a Maven dependency

To configure the JDBC driver as a Maven dependency

  1. Add the following repository to the repositories section of your pom.xml file.

    Note

    The URL in the following code example returns an error if used in a browser. Use this URL only in the context of a Maven project.

    <repositories> <repository> <id>redshift</id> <url>http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release</url> </repository> </repositories>

    To connect using SSL, add the following repository to your pom.xml file.

    <repositories> <repository> <id>redshift</id> <url>https://s3.amazonaws.com/redshift-maven-repository/release</url> </repository> </repositories>
  2. Declare the version of the driver that you want to use in the dependencies section of your pom.xml file.

    Amazon Redshift offers drivers for tools that are compatible with the JDBC 4.2 API. For information about the functionality supported by these drivers, see Download an Amazon Redshift JDBC driver.

    Add a dependency for the driver from the following list.

    Replace driver-version in the following example with your driver version. For example, 2.0.0.0.

    • JDBC 4.2–compatible driver:

      <dependency> <groupId>com.amazon.redshift</groupId> <artifactId>redshift-jdbc42</artifactId> <version>driver-version</version> </dependency>

      The class name for this driver is com.amazon.redshift.jdbc42.Driver.

The Amazon Redshift Maven drivers need the following optional dependencies when you use IAM database authentication.

<dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-core</artifactId> <version>1.11.118</version> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-redshift</artifactId> <version>1.11.118</version> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-sts</artifactId> <version>1.11.118</version> <scope>runtime</scope> <optional>true</optional> </dependency>

If your tool requires a specific previous version of a driver, see Use previous JDBC driver versions with Maven.

Upgrading the driver to the latest version

To upgrade or change the Amazon Redshift JDBC driver to the latest version, first modify the version section of the dependency to the latest version of the driver. Then clean your project with the Maven Clean Plugin, as shown following.

mvn clean