Struts is a classic Java web framework, and if you're building enterprise-grade applications that need Powerhouse analytics, integrating Teradata makes a lot of sense. While there's no official Teradata Docker image for the full database, you can simulate local development using Teradata’s free Vantage Express VM, containerized JDBC layers, or a remote test tier. This guide focuses on setting it up in Struts—using Docker or dev-tier for dev, Kubernetes for production—keeping everything clean, configurable, and environment-specific.
1. Add Dependencies in pom.xml
Start by updating your
pom.xml
to include Struts, Teradata JDBC, and Kubernetes client support:
<dependencies>
<!-- Struts core framework -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts.version}</version>
</dependency>
<!-- Teradata JDBC driver -->
<dependency>
<groupId>com.teradata.jdbc</groupId>
<artifactId>terajdbc4</artifactId>
<version>${teradata.jdbc.version}</version>
</dependency>
<!-- Kubernetes client for production config -->
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>${fabric8.version}</version>
</dependency>
</dependencies>
This gives you Struts for your web layer, Teradata connectivity, and optional Kubernetes integration for managing prod settings.
2. Set Up Teradata for Development
Teradata doesn’t provide a full database Docker image so for development, you have a few options:
- Teradata Vantage Express VM on your local machine (free tier)
- Remote Dev/Sandbox Teradata instance
- Container running Teradata clients to connect to a hosted instance
For example, run the official Vantage Express image or your hosted Teradata instance on
localhost:1025
, with credentials like
devuser/devpass
.
3. Create Dev Config: teradata-dev.properties
Add this under
src/main/resources
:
db.driver=com.teradata.jdbc.TeraDriver
db.url=jdbc:teradata://localhost/DATABASE=mydb
db.user=devuser
db.password=devpass
db.validationQuery=SELECT 1
Load it in your Struts helper or DAO:
Properties props = new Properties();
props.load(getClass().getResourceAsStream("/teradata-dev.properties"));
Class.forName(props.getProperty("db.driver"));
try (Connection conn = DriverManager.getConnection(
props.getProperty("db.url"),
props.getProperty("db.user"),
props.getProperty("db.password"));
Statement stmt = conn.createStatement()) {
stmt.executeQuery(props.getProperty("db.validationQuery"));
}
This simulates a Teradata workflow during development.
4. Prepare Kubernetes Configs for Production
In production, hold credentials outside your code using ConfigMaps and Secrets:
kubectl create configmap teradata-config \
--from-literal=DB_URL=jdbc:teradata://teradata-service/DATABASE=proddb \
--from-literal=DB_DRIVER=com.teradata.jdbc.TeraDriver \
--from-literal=DB_VALIDATION_QUERY=SELECT 1
kubectl create secret generic teradata-secret \
--from-literal=DB_USER=produser \
--from-literal=DB_PASSWORD=prodSecret123
5. Add Production Config: teradata-prod.properties
Include this in your application's resources:
db.driver=${DB_DRIVER}
db.url=${DB_URL}
db.user=${DB_USER}
db.password=${DB_PASSWORD}
db.validationQuery=${DB_VALIDATION_QUERY}
At runtime, environment variables supplied by Kubernetes will be automatically substituted.
6. Kubernetes Deployment Snippet
Make sure your deployment manifest provides these environment variables:
env:
- name: DB_DRIVER
valueFrom:
configMapKeyRef:
name: teradata-config
key: DB_DRIVER
- name: DB_URL
valueFrom:
configMapKeyRef:
name: teradata-config
key: DB_URL
- name: DB_VALIDATION_QUERY
valueFrom:
configMapKeyRef:
name: teradata-config
key: DB_VALIDATION_QUERY
- name: DB_USER
valueFrom:
secretKeyRef:
name: teradata-secret
key: DB_USER
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: teradata-secret
key: DB_PASSWORD
Your Struts app will automatically load appropriate values at startup.
7. Struts Action for Health Check
Here’s a clean example to test connectivity:
public class DbHealthAction extends ActionSupport {
public String execute() {
String url = System.getenv("DB_URL");
String user = System.getenv("DB_USER");
String pass = System.getenv("DB_PASSWORD");
String validation = System.getenv("DB_VALIDATION_QUERY");
try (Connection conn = DriverManager.getConnection(url, user, pass);
Statement stmt = conn.createStatement()) {
stmt.executeQuery(validation);
addActionMessage("Connected to Teradata successfully!");
return SUCCESS;
} catch (SQLException e) {
addActionError("Connection failed: " + e.getMessage());
return ERROR;
}
}
}
Same code works for both dev and prod—only properties change.
Why This Setup Works
- Quick local iteration: VM or hosted instance simulates real Teradata
- Secure production: Credentials never in code—managed by Kubernetes
- Consistent codebase: One single connection logic for all environments
- Clean config separation:
.properties
files reduce cross-env errors
Even without an official Teradata Docker image, you can still develop locally with Vantage Express, and deploy securely with Kubernetes. Combining Struts, JDBC, and environment-managed configs gives you a clean, maintainable approach to connecting with Teradata—whether you're learning, prototyping, or going full production. Good luck building your scalable, enterprise-ready Struts app!
image quote pre code