From f2a49eb5c0877019775a67065c2d561a0505e7e4 Mon Sep 17 00:00:00 2001 From: Daniel Herrera Date: Tue, 9 Jun 2026 16:13:47 +0200 Subject: [PATCH 1/2] Updated jdbc, jupyter and local_jupyter_hub guides --- quickstarts/analyze-data/jupyter.md | 101 ++++++---- quickstarts/analyze-data/local-jupyter-hub.md | 51 ++--- quickstarts/create-applications/jdbc.md | 177 +++++++++++------- 3 files changed, 204 insertions(+), 125 deletions(-) diff --git a/quickstarts/analyze-data/jupyter.md b/quickstarts/analyze-data/jupyter.md index 5b24bbbeba..e38b499d7e 100644 --- a/quickstarts/analyze-data/jupyter.md +++ b/quickstarts/analyze-data/jupyter.md @@ -1,43 +1,43 @@ --- sidebar_position: 1 id: jupyter -title: Use Vantage from a Jupyter notebook -author: Adam Tworkiewicz -email: adam.tworkiewicz@teradata.com -page_last_update: November 10th, 2022 -description: Use Teradata Vantage from a Jupyter notebook -keywords: [data warehouses, compute storage separation, teradata, vantage, cloud data platform, JDBC, java applications, business intelligence, enterprise analytics, jupyter, teradatasql, ipython-sql, teradatasqlalchemy] +title: Use Teradata Database from a Jupyter notebook +author: Adam Tworkiewicz, Daniel Herrera +email: developer.relations@teradata.com +page_last_update: June 9th, 2026 +description: Use Teradata Database from a Jupyter notebook +keywords: [data warehouses, compute storage separation, teradata, teradata database, cloud data platform, JDBC, java applications, business intelligence, enterprise analytics, jupyter, teradatasql, jupysql, teradatasqlalchemy] --- import JupyterTrialsNote from '../_partials/jupyter_notebook_trials_note.mdx'; import TrialDocsNote from '../_partials/teradata_trial.mdx' -import CommunityLink from '../_partials/community_link.mdx' -# Use Vantage from a Jupyter notebook + +# Use Teradata Database from a Jupyter notebook ## Overview -In this how-to we will go through the steps for connecting to Teradata Vantage from a Jupyter notebook. +In this how-to we will go through the steps for connecting to Teradata Database from a Jupyter notebook. ## Options -There are a couple of ways to connect to Vantage from a Jupyter Notebook: +There are a couple of ways to connect to Teradata Database from a Jupyter Notebook: 1. [Use python or R libraries in a regular Python/R kernel notebook](#teradata-libraries) - this option works well when you are in a restricted environment that doesn't allow you to spawn your own Docker images. Also, it's useful in traditional datascience scenarios when you have to mix SQL and Python/R in a notebook. If you are proficient with Jupyter and have your own set of preferred libraries and extensions, start with this option. -2. [Use the Teradata Jupyter Docker image](#teradata-jupyter-docker-image) - the Teradata Jupyter Docker image bundles the Teradata SQL kernel (more on this later), `teradataml` and `tdplyr` libraries, python and R drivers. It also contains Jupyter extensions that allow you to manage Teradata connections, explore objects in Vantage database. It's convenient when you work a lot with SQL or would find a visual Navigator helpful. If you are new to Jupyter or if you prefer to get a currated assembly of libraries and extensions, start with this option. +2. [Use the Teradata Jupyter Docker image](#teradata-jupyter-docker-image) - the Teradata Jupyter Docker image bundles the Teradata SQL kernel (more on this later), `teradataml` and `tdplyr` libraries, python and R drivers. It also contains Jupyter extensions that allow you to manage Teradata connections, explore objects in Teradata Database. It's convenient when you work a lot with SQL or would find a visual Navigator helpful. If you are new to Jupyter or if you prefer to get a currated assembly of libraries and extensions, start with this option. ### Teradata libraries -This option uses a regular Jupyter Lab notebook. We will see how to load the Teradata Python driver and use it from Python code. We will also examine `ipython-sql` extension that adds support for SQL-only cells. +This option uses a regular Jupyter Lab notebook. We will see how to load the Teradata Python driver and use it from Python code. We will also examine the `jupysql` extension that adds support for SQL-only cells. -1. We start with a plain Jupyter Lab notebook. Here, I'm using docker but any method of starting a notebook, including Jupyter Hub, Google Cloud AI Platform Notebooks, AWS SageMaker Notebooks, Azure ML Notebooks will do. +1. We start with a plain Jupyter Lab notebook. Here, we're using docker but any method of starting a notebook, including Jupyter Hub, Google Cloud AI Platform Notebooks, AWS SageMaker Notebooks, Azure ML Notebooks will do. ```bash -docker run --rm -p 8888:8888 -e JUPYTER_ENABLE_LAB=yes \ - -v "${PWD}":/home/jovyan/work jupyter/datascience-notebook +docker run --rm -p 8888:8888 \ + -v "${PWD}":/home/jovyan/work quay.io/jupyter/datascience-notebook ``` 2. Docker logs will display the url that you need to go to: @@ -54,42 +54,59 @@ Or copy and paste one of these URLs: 3. We will open a new notebook and create a cell to install the required libraries: :::note -I've published a notebook with all the cells described below on GitHub: https://github.com/Teradata/quickstarts/blob/main/modules/ROOT/attachments/vantage-with-python-libraries.ipynb +We've published a notebook with all the cells described below on GitHub: https://github.com/Teradata/quickstarts/blob/main/modules/ROOT/attachments/vantage-with-python-libraries.ipynb ::: -```bash -import sys -!{sys.executable} -m pip install teradatasqlalchemy +```python +%pip install teradatasqlalchemy ``` -4. Now, we will import `Pandas` and define the connection string to connect to Teradata. Since I'm running my notebook in Docker on my local machine and I want to connect to a local Vantage Express VM, I'm using `host.docker.internal` DNS name provided by Docker to reference the IP of my machine. +4. Now, we will import `Pandas` and define the connection string to connect to Teradata. -```bash +:::note +The connection string format is `teradatasql://username:password@host/database`. Replace ``, ``, and `` with your Teradata instance details. If you are connecting to a local Vantage Express VM from inside Docker on the same machine, use the special `host.docker.internal` hostname that Docker provides to reach the host machine. +::: + +```python import pandas as pd # Define the db connection string. Pandas uses SQLAlchemy connection strings. -# For Teradata Vantage, it's teradatasql://username:password@host/database_name . +# For Teradata Database, it's teradatasql://username:password@host/database_name . # See https://pypi.org/project/teradatasqlalchemy/ for details. -db_connection_string = "teradatasql://dbc:dbc@host.docker.internal/dbc" + +# For a remote/cloud/trial Teradata instance: +db_connection_string = "teradatasql://:@/dbc" + +# For a local Vantage Express VM (running on the same machine as Docker): +# db_connection_string = "teradatasql://dbc:dbc@host.docker.internal/dbc" ``` -5. I can now call Pandas to query Vantage and move the result to a Pandas dataframe: -```bash +5. Now we can call Pandas to query Teradata and move the result to a Pandas dataframe: +```python pd.read_sql("SELECT * FROM dbc.dbcinfo", con = db_connection_string) ``` -6. The syntax above is concise but it can get tedious if all you need is to explore data in Vantage. We will use `ipython-sql` and its `%%sql` magic to create SQL-only cells. We start with importing the required libraries. -```bash -import sys -!{sys.executable} -m pip install ipython-sql teradatasqlalchemy +6. The syntax above is concise but it can get tedious if all you need is to explore data in Teradata. We will use `jupysql` and its `%%sql` magic to create SQL-only cells. We start with installing the required libraries. + +:::note +`jupysql` is the actively maintained successor to `ipython-sql`. It provides the same `%sql` / `%%sql` magic API and is compatible with current versions of all dependencies. +::: + +```python +%pip install jupysql teradatasqlalchemy ``` -7. We load `ipython-sql` and define the db connection string: -```bash +7. We load `jupysql` and define the db connection string: +```python %load_ext sql # Define the db connection string. The sql magic uses SQLAlchemy connection strings. -# For Teradata Vantage, it's teradatasql://username:password@host/database_name . +# For Teradata Database, it's teradatasql://username:password@host/database_name . # See https://pypi.org/project/teradatasqlalchemy/ for details. -%sql teradatasql://dbc:dbc@host.docker.internal/dbc + +# For a remote/cloud/trial Teradata instance: +%sql teradatasql://:@/dbc + +# For a local Vantage Express VM (running on the same machine as Docker): +# %sql teradatasql://dbc:dbc@host.docker.internal/dbc ``` 8. We can now use `%sql` and `%%sql` magic. Let's say we want to explore data in a table. We can create a cell that says: @@ -104,11 +121,11 @@ result = %sql SELECT * FROM dbc.dbcinfo result.DataFrame() ``` -There are many other features that ipython-sql provides, including variable substitution, plotting with `matplotlib`, writting results to a local csv file or back to the database. See [the demo notebook](https://github.com/Teradata/quickstarts/blob/main/modules/ROOT/attachments/vantage-with-python-libraries.ipynb) for examples and [ipython-sql github repo](https://github.com/catherinedevlin/ipython-sql/) for a complete reference. +There are many other features that jupysql provides, including variable substitution, plotting with `matplotlib`, writing results to a local csv file or back to the database. See [the demo notebook](https://github.com/Teradata/quickstarts/blob/main/modules/ROOT/attachments/vantage-with-python-libraries.ipynb) for examples and [jupysql documentation](https://jupysql.ploomber.io/) for a complete reference. ### Teradata Jupyter Docker image -The Teradata Jupyter Docker image builds on `jupyter/datascience-notebook` Docker image. It adds the Teradata SQL kernel, Teradata Python and R libraries, Jupyter extensions to make you productive while interacting with Teradata Vantage. The image also contains sample notebooks that demonstrate how to use the SQL kernel and Teradata libraries. +The Teradata Jupyter Docker image builds on `quay.io/jupyter/datascience-notebook` Docker image. It adds the Teradata SQL kernel, Teradata Python and R libraries, Jupyter extensions to make you productive while interacting with Teradata Database. The image also contains sample notebooks that demonstrate how to use the SQL kernel and Teradata libraries. The SQL kernel and Teradata Jupyter extensions are useful for people that spend a lot of time with the SQL interface. Think about it as a notebook experience that, in many cases, is more convenient than using Teradata Studio. The Teradata Jupyter Docker image doesn't try to replace Teradata Studio. It doesn't have all the features. It's designed for people who need a lightweight, web-based interface and enjoy the notebook UI. @@ -117,17 +134,17 @@ The Teradata Jupyter Docker image can be used when you want to run Jupyter local 1. Run the image: :::note -By passing `-e "accept_license=Y` you accept [the license agreement](https://github.com/Teradata/jupyterextensions/blob/master/licensefiles/license.txt) for Teradata Jupyter Extensions. +By passing `-e "accept_license=Y"` you accept [the license agreement](https://github.com/Teradata/jupyterextensions/blob/master/licensefiles/license.txt) for Teradata Jupyter Extensions. ::: ```bash docker volume create notebooks -docker run -e "accept_license=Y" -p :8888:8888 \ +docker run -e "accept_license=Y" -p 8888:8888 \ -v notebooks:/home/jovyan/JupyterLabRoot \ teradata/jupyterlab-extensions ``` -2. Docker logs will display the url that you need to go to. For example, this is what I've got: +2. Docker logs will display the url that you need to go to. For example, this is what we've got: ```bash Starting JupyterLab ... Docker Build ID = 3.2.0-ec02012022 @@ -144,13 +161,15 @@ Enter this URL in your browser: http://localhost:8888?token=96a3ab874a03779c400 ![GettingStartedDemo.ipynb ](../images/gettingstarteddemo.ipynb.png) +:::note +Steps 3 and 4 require a desktop browser. If you are running in a headless or server environment, you can connect to Teradata programmatically using the `teradataml` Python library — see [Option 1](#teradata-libraries) for an example that works without a browser. +::: + ## Summary -This quick start covered different options to connect to Teradata Vantage from a Jupyter Notebook. We learned about the Teradata Jupyter Docker image that bundles multiple Teradata Python and R libraries. It also provides an SQL kernel, database object explorer and connection management. These features are useful when you spend a lot of time with the SQL interface. For more traditional data science scenarios, we explored the standalone Teradata Python driver and integration through the ipython sql extension. +This quick start covered different options to connect to Teradata Database from a Jupyter Notebook. We learned about the Teradata Jupyter Docker image that bundles multiple Teradata Python and R libraries. It also provides an SQL kernel, database object explorer and connection management. These features are useful when you spend a lot of time with the SQL interface. For more traditional data science scenarios, we explored the standalone Teradata Python driver and integration through the `jupysql` extension. ## Further reading * [Teradata Jupyter Extensions Website](https://teradata.github.io/jupyterextensions) * [Teradata Vantage™ Modules for Jupyter Installation Guide](https://docs.teradata.com/r/KQLs1kPXZ02rGWaS9Ktoww/root) * [Teradata® Package for Python User Guide](https://docs.teradata.com/r/1YKutX2ODdO9ppo_fnguTA/root) - - \ No newline at end of file diff --git a/quickstarts/analyze-data/local-jupyter-hub.md b/quickstarts/analyze-data/local-jupyter-hub.md index ed2fc19b9f..ebf4404314 100644 --- a/quickstarts/analyze-data/local-jupyter-hub.md +++ b/quickstarts/analyze-data/local-jupyter-hub.md @@ -2,15 +2,14 @@ sidebar_position: 2 id: local-jupyter-hub title: Deploy Teradata Jupyter extensions to JupyterHub -author: Hailing Jiang -email: Hailing.iang@teradata.com -page_last_update: November 17th, 2021 +author: Hailing Jiang, Daniel Herrera +email: developer.relations@teradata.com +page_last_update: June 9th, 2026 description: Deploy Teradata Jupyter extensions in customer JupyterHub clusters -keywords: [data warehouses, compute storage separation, teradata, vantage, cloud data platform, java applications, business intelligence, enterprise analytics, jupyter, teradatasql, ipython-sql, teradatasqlalchemy] +keywords: [data warehouses, compute storage separation, teradata, teradata database, cloud data platform, java applications, business intelligence, enterprise analytics, jupyter, teradatasql, ipython-sql, teradatasqlalchemy] --- import TrialDocsNote from '../_partials/teradata_trial.mdx' -import CommunityLink from '../_partials/community_link.mdx' # Deploy Teradata Jupyter extensions to JupyterHub @@ -21,24 +20,28 @@ For customers who have their own JupyterHub clusters, there are two options to i 1. Use Teradata Jupyter Docker image. 2. Customize an existing Docker image to include Teradata extensions. -This page contains detailed instructions on the two options. Instructions are based on the assumption that the customer JupyterHub deployment is based on [Zero to JupyterHub with Kubernetes](https://zero-to-jupyterhub.readthedocs.io/en/latest/index.html). +This page contains detailed instructions on the two options. Instructions are based on the assumption that the customer JupyterHub deployment is based on [Zero to JupyterHub with Kubernetes](https://zero-to-jupyterhub.readthedocs.io/en/latest/index.html). ## Use Teradata Jupyter Docker image -Teradata provides a ready-to-run Docker image that builds on the [jupyter/datascience-notebook](https://hub.docker.com/r/jupyter/datascience-notebook/) image. It bundles the Teradata SQL kernel, Teradata Python and R libraries and drivers and Teradata extensions for Jupyter to make you productive while interacting with Teradata database. The image also contains sample notebooks that demonstrate how to use the SQL kernel, extensions and Teradata libraries. +Teradata provides a ready-to-run Docker image that builds on the [jupyter/datascience-notebook](https://hub.docker.com/r/jupyter/datascience-notebook/) image. It bundles the Teradata SQL kernel, Teradata Python and R libraries and drivers and Teradata extensions for Jupyter to make you productive while interacting with Teradata Database. The image also contains sample notebooks that demonstrate how to use the SQL kernel, extensions and Teradata libraries. You can use this image in the following ways: * Start a personal Jupyter Notebook server in a local Docker container * Run JupyterLab servers for a team using JupyterHub -For instructions to start a personal JupyterLab server in a local Docker container, please see [installation guide](https://docs.teradata.com/r/KQLs1kPXZ02rGWaS9Ktoww/Fwvns7y_a7juDWx1NixC2A). This section will focus on how to use the  Teradata Jupyter Docker image in a customer's existing JupyterHub environment. +For instructions to start a personal JupyterLab server in a local Docker container, please see [installation guide](https://docs.teradata.com/r/KQLs1kPXZ02rGWaS9Ktoww/Fwvns7y_a7juDWx1NixC2A). This section will focus on how to use the Teradata Jupyter Docker image in a customer's existing JupyterHub environment. ### Install Teradata Jupyter Docker image in your registry -1. Go to [Vantage Modules for Jupyter](https://downloads.teradata.com/download/tools/vantage-modules-for-jupyter) page and download the Docker image. It is a tarball with name in this format `teradatajupyterlabext_VERSION.tar.gz`. +:::note +Downloading from `downloads.teradata.com` requires an authenticated Teradata customer account. Contact your Teradata representative if you do not have one. +::: + +1. Go to [Teradata Modules for Jupyter](https://downloads.teradata.com/download/tools/vantage-modules-for-jupyter) page and download the Docker image. It is a tarball with name in this format `teradatajupyterlabext_VERSION.tar.gz`. 2. Load the image: ```bash @@ -47,7 +50,7 @@ docker load -i teradatajupyterlabext_VERSION.tar.gz 3. Push the image to your Docker registry: ```bash -docker push +docker push REGISTRY_URL/teradatajupyterlabext_VERSION ``` :::tip @@ -62,11 +65,11 @@ docker tag OLD_IMAGE_NAME NEW_IMAGE_NAME 1. To use the Teradata Jupyter Docker image directly in your JupyterHub cluster, modify the override file as described in [herein the JupyterHub documentation](https://zero-to-jupyterhub.readthedocs.io/en/latest/jupyterhub/customizing/user-environment.html#choose-and-use-an-existing-docker-image). Replace `REGISTRY_URL` and `VERSION` with appropriate values from the step above: -```bash +```yaml singleuser: image: - name: REGISTRY_URL/teradatajupyterlabext_VERSION - tag: latest + name: REGISTRY_URL/teradatajupyterlabext_VERSION + tag: latest ``` 2. Apply the changes to the cluster as described in [JupyterHub documentation](https://zero-to-jupyterhub.readthedocs.io/en/latest/jupyterhub/customizing/extending-jupyterhub.html#applying-configuration-changes). @@ -80,8 +83,8 @@ You can use multiple profiles to allow users to select which image they want to If your users need some packages or notebooks that are not bundled in the Teradata Jupyter Docker image, we recommend that you use Teradata image as a base image and build a new one on top of it. Here is an example Dockerfile that builds on top of Teradata image and adds additional packages and notebooks. Use the Dockerfile to build a new Docker image, push the image to a designated registry, modify override file as shown above to use the new image as singleuser image, apply the changes to the cluster as described above. Replace `REGISTRY_URL` and `VERSION` with appropriate values: - -```bash + +```dockerfile FROM REGISTRY_URL/teradatajupyterlabext_VERSION:latest # install additional packages @@ -93,13 +96,17 @@ COPY notebooks/. /tmp/JupyterLabRoot/DemoNotebooks/ ## Customize an existing Docker image to include Teradata extensions -If you prefer, you can include the Teradata SQL kernel and extensions into into an existing image you are currently using. +If you prefer, you can include the Teradata SQL kernel and extensions into an existing image you are currently using. + +:::note +Downloading from `downloads.teradata.com` requires an authenticated Teradata customer account. Contact your Teradata representative if you do not have one. +::: -1. Go to [Vantage Modules for Jupyter](https://downloads.teradata.com/download/tools/vantage-modules-for-jupyter) page to download the zipped Teradata Jupyter extensions package bundle.  Assuming your existing docker image is Linux based, you will want to use the Linux version of the download.  Otherwise, download for the platform you are using. The `.zip` file contains the Teradata SQL Kernel, extensions and sample notebooks. +1. Go to [Teradata Modules for Jupyter](https://downloads.teradata.com/download/tools/vantage-modules-for-jupyter) page to download the zipped Teradata Jupyter extensions package bundle. Assuming your existing docker image is Linux based, you will want to use the Linux version of the download. Otherwise, download for the platform you are using. The `.zip` file contains the Teradata SQL Kernel, extensions and sample notebooks. 2. Unzip the bundle file to your working directory. 3. Below is an example Dockerfile to add Teradata Jupyter extensions to your existing Docker image. Use the Dockerfile to build a new Docker image, push the image to a designated registry, modify override file as shown above to use the new image as singleuser image, apply the changes to the cluster: - ```bash + ```dockerfile FROM REGISTRY_URL/your-existing-image:tag ENV NB_USER=jovyan \ HOME=/home/jovyan \ @@ -143,6 +150,10 @@ If you prefer, you can include the Teradata SQL kernel and extensions into into WORKDIR $EXT_DIR + # TODO: replace the lines below with the current pip-based installation + # commands from https://teradata.github.io/jupyterextensions + # The jupyter labextension install approach below is deprecated in + # JupyterLab 3+ and will fail without Node.js. See report.md Issue #3. RUN jupyter labextension install --no-build teradata_database* && \ jupyter labextension install --no-build teradata_resultset* && \ jupyter labextension install --no-build teradata_sqlhighlighter* && \ @@ -166,7 +177,5 @@ If you prefer, you can include the Teradata SQL kernel and extensions into into ## Further reading * [Teradata Jupyter Extensions Website](https://teradata.github.io/jupyterextensions) -* [Teradata Vantage™ Modules for Jupyter Installation Guide](https://docs.teradata.com/r/KQLs1kPXZ02rGWaS9Ktoww/root) +* [Teradata Modules for Jupyter Installation Guide](https://docs.teradata.com/r/KQLs1kPXZ02rGWaS9Ktoww/root) * [Teradata® Package for Python User Guide](https://docs.teradata.com/r/1YKutX2ODdO9ppo_fnguTA/root) - - diff --git a/quickstarts/create-applications/jdbc.md b/quickstarts/create-applications/jdbc.md index 30c6a11b35..b4d9980534 100644 --- a/quickstarts/create-applications/jdbc.md +++ b/quickstarts/create-applications/jdbc.md @@ -1,117 +1,168 @@ --- sidebar_position: 1 id: jdbc -author: Adam Tworkiewicz -email: adam.tworkiewicz@teradata.com -page_last_update: November 14th, 2022 -description: How to connect to Teradata Vantage using JDBC. -keywords: [data warehouses, compute storage separation, teradata, vantage, cloud data platform, JDBC, java applications, business intelligence, enterprise analytics] +author: Adam Tworkiewicz, Daniel Herrera +email: developer.relations@teradata.com +page_last_update: June 9th, 2026 +description: How to connect to Teradata Database using JDBC. +keywords: [data warehouses, compute storage separation, teradata, teradata database, cloud data platform, JDBC, java applications, business intelligence, enterprise analytics] --- import TrialDocsNote from '../_partials/teradata_trial.mdx' -import CommunityLink from '../_partials/community_link.mdx' -# Connect to Vantage using JDBC +# Connect to Teradata Database using JDBC ## Overview -This how-to demonstrates how to connect to Teradata Vantage using JDBC using a sample Java application: [GitHub JDBC](https://github.com/Teradata/jdbc-sample-app). +This how-to demonstrates how to connect to Teradata Database using JDBC using a sample Java application. ## Prerequisites -* Access to a Teradata Vantage instance. +* Access to a Teradata Database instance. -* JDK +* JDK 11+ * Maven -## Add dependency to your maven project +:::tip 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](https://maven.apache.org/download.cgi) +::: -Add the Teradata JDBC driver as a dependency to your Maven POM XML file: +## Create a Maven project +Create a new Maven project using the standard quickstart archetype: + +```bash +mvn archetype:generate \ + -DgroupId=com.teradata.app \ + -DartifactId=jdbc-sample-app \ + -DarchetypeArtifactId=maven-archetype-quickstart \ + -DarchetypeVersion=1.4 \ + -DinteractiveMode=false +cd jdbc-sample-app +``` + +## 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: ```xml - - com.teradata.jdbc - terajdbc - 20.00.00.06 - + + + 4.0.0 + + com.teradata.app + jdbc-sample-app + 1.0-SNAPSHOT + + + UTF-8 + 11 + + + + + com.teradata.jdbc + terajdbc + 20.00.00.06 + + + junit + junit + 4.13.2 + test + + + ``` + ## Code to send a query :::note -This step assumes that your Vantage database is available on `localhost` on port `1025`. If you are running Vantage Express on your laptop, you need to expose the port from the VM to the host machine. Refer to your virtualization software documentation how to forward ports. +Replace ``, ``, and `` 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. ::: -The project is set up. All that is left, is to load the driver, pass connection and authentication parameters and run a query: +Replace `src/main/java/com/teradata/app/App.java` with the following: ```java package com.teradata.app; - + import java.sql.*; - + public class App { - static final String DB_URL = "jdbc:teradata://localhost"; - static final String USER = "dbc"; - static final String PASS = "dbc"; + static final String DB_URL = "jdbc:teradata://"; + static final String USER = ""; + static final String PASS = ""; static final String QUERY = "SELECT * FROM dbc.dbcinfo"; - + public static void main(String[] args) { - App app = new App(); - app.query(); + new App().query(); } - + public void query() { - Connection conn = null; - Statement stmt = null; - ResultSet rs = null; - - // Open a connection - try { - conn = DriverManager.getConnection(DB_URL, USER, PASS); - stmt = conn.createStatement(); - rs = stmt.executeQuery(QUERY); - - // Extract data from result set + try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS); + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(QUERY)) { + while (rs.next()) { - System.out.println(String.format("setting: %s, value: %s", rs.getString(1), rs.getString(2))); + System.out.println(String.format("setting: %s, value: %s", + rs.getString(1), rs.getString(2))); } } catch (SQLException e) { - e.printStackTrace(); - } finally { - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { /* Ignored */} - } - if (stmt != null) { - try { - stmt.close(); - } catch (SQLException e) { /* Ignored */} - } - if (conn != null) { - try { - conn.close(); - } catch (SQLException e) { /* Ignored */} - } + throw new RuntimeException("Failed to connect or query Teradata", e); } } } ``` -### Run the tests +## Add a test + +Replace `src/test/java/com/teradata/app/AppTest.java` with the following: -Run the tests: +:::note +The test connects to your live Teradata Database instance, so it requires the credentials you set in `App.java` to be valid and the instance to be reachable. +::: + +```java +package com.teradata.app; + +import org.junit.Test; + +public class AppTest { + @Test + public void shouldConnectAndQueryTeradata() { + new App().query(); + } +} ``` + +### Run the tests + +```bash mvn test ``` +You should see output similar to: + +``` +setting: VERSION, value: 20.00.xx.xx +setting: LANGUAGE SUPPORT MODE, value: Standard +setting: RELEASE, value: 20.00.xx.xx +[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 +[INFO] BUILD SUCCESS +``` + ## Summary -This how-to demonstrated how to connect to Teradata Vantage 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 Vantage. +This how-to demonstrated how to connect to Teradata Database 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 -* [Teradata JDBC Driver Reference](https://teradata-docs.s3.amazonaws.com/doc/connectivity/jdbc/reference/current/frameset.html) - - \ No newline at end of file +* [Teradata JDBC Driver Reference](https://teradata-docs.s3.amazonaws.com/doc/connectivity/jdbc/reference/current/frameset.html) \ No newline at end of file From 34dcd98a63c66bdfe0bd54bf5340e6bf0eb2638b Mon Sep 17 00:00:00 2001 From: Daniel Herrera Date: Thu, 18 Jun 2026 16:03:17 +0200 Subject: [PATCH 2/2] modify git ignore to add temp folder used for Copilot Memory across sessions --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index cd6ecdc3dc..14679c0f17 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ static/~partytown npm-debug.log* yarn-debug.log* yarn-error.log* + +# Temporary local notes +.temp/