Skip to main content
Join our research panel and help shape the future of Teradata.Sign up.

Connect to Teradata using JDBC

Overview

This how-to demonstrates how to connect to Teradata using JDBC using a sample Java application.

Prerequisites

  • Access to a Teradata instance.
Note

If you need a test instance of Teradata, you can provision one for free at https://www.teradata.com/try

  • JDK 11+
  • Maven
Installing Maven

If Maven is not installed on your system:

  • macOS: brew install maven
  • Windows: winget install ApacheMaven or choco install maven
  • Linux (Debian/Ubuntu): sudo apt install maven
  • All platforms: Download from maven.apache.org

Create a Maven project

Create a new Maven project using the standard quickstart archetype:

Add dependency to your maven project

Replace the contents of pom.xml with the following. This adds the Teradata JDBC driver and sets the compiler to Java 11:

Code to send a query

Note

Replace <host>, <user>, and <password> with your Teradata environment credentials. If you are running Vantage Express, the default host is localhost, user is dbc, and password is dbc. You may need to expose port 1025 from your VM to the host machine — refer to your virtualization software documentation on how to forward ports.

Replace src/main/java/com/teradata/app/App.java with the following:

Add a test

Replace src/test/java/com/teradata/app/AppTest.java with the following:

Note

The test connects to your live Teradata instance, so it requires the credentials you set in App.java to be valid and the instance to be reachable.

Run the tests

You should see output similar to:

Summary

This how-to demonstrated how to connect to Teradata using JDBC. It described a sample Java application with Maven as the build tool that uses the Teradata JDBC driver to send SQL queries to Teradata Database.

Further reading