#1
Struts is a mature Java web framework, and if you're building enterprise-grade applications, OracleDB remains a popular relational database choice. This guide walks you through integrating OracleDB into a Struts project—covering local development using Docker and production deployment using Kubernetes—while keeping your configurations clean and environment-specific.

1. Add Dependencies in pom.xml

Add the following dependencies to enable Struts, Oracle JDBC, and Kubernetes support:
<dependencies>
  <!-- Struts core framework -->
  <dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>${struts.version}</version>
  </dependency>

  <!-- Oracle JDBC driver -->
  <dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>${oracle.jdbc.version}</version>
  </dependency>

  <!-- Kubernetes client (optional) -->
  <dependency>
    <groupId>io.fabric8</groupId>
    <artifactId>kubernetes-client</artifactId>
    <version>${fabric8.version}</version>
  </dependency>
</dependencies>
Struts powers your web layer, the Oracle driver enables database connectivity, and optionally you can interact with Kubernetes in production.

2. Run OracleDB with Docker Locally

Spin up Oracle Database Express Edition using Docker:
docker run -d --name oracle-dev \
  -p 1521:1521 \
  -e ORACLE_PWD=DevPass123 \
  gvenzl/oracle-xe:latest
This gives you Oracle XE at localhost:1521, with the default PDB named XEPDB1 and password DevPass123.

3. Create Dev Configuration: oracle-dev.properties

Add the following properties under src/main/resources:
db.driver=oracle.jdbc.OracleDriver
db.url=jdbc:oracle:thin:@localhost:1521/XEPDB1
db.user=system
db.password=DevPass123
db.validationQuery=SELECT 1 FROM DUAL
Use a Struts helper or DAO to load and apply them:
Properties props = new Properties();
props.load(getClass().getResourceAsStream("/oracle-dev.properties"));

Class.forName(props.getProperty("db.driver"));
Connection conn = DriverManager.getConnection(
  props.getProperty("db.url"),
  props.getProperty("db.user"),
  props.getProperty("db.password")
);
// Optionally test query
try (Statement stmt = conn.createStatement()) {
  stmt.executeQuery(props.getProperty("db.validationQuery"));
}
This enables OracleDB connectivity during development.

4. Prepare Kubernetes for Production

In production, avoid hardcoding sensitive settings by using Kubernetes ConfigMaps and Secrets:
kubectl create configmap oracle-config \
  --from-literal=DB_URL=jdbc:oracle:thin:@oracle-svc:1521/ORCLPDB1 \
  --from-literal=DB_DRIVER=oracle.jdbc.OracleDriver \
  --from-literal=DB_VALIDATION_QUERY=SELECT+1+FROM+DUAL

kubectl create secret generic oracle-secret \
  --from-literal=DB_USER=produser \
  --from-literal=DB_PASSWORD=ProdPass456
This ensures secure config management elsewhere than your codebase.

5. Create Production Config: oracle-prod.properties

Include this file 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}

Your helper code remains unchanged—values are picked up from environment at runtime.

6. Kubernetes Deployment Snippet

Add this to your Pod specification to inject config into the environment:
env:
  - name: DB_DRIVER
    valueFrom:
      configMapKeyRef:
        name: oracle-config
        key: DB_DRIVER
  - name: DB_URL
    valueFrom:
      configMapKeyRef:
        name: oracle-config
        key: DB_URL
  - name: DB_VALIDATION_QUERY
    valueFrom:
      configMapKeyRef:
        name: oracle-config
        key: DB_VALIDATION_QUERY
  - name: DB_USER
    valueFrom:
      secretKeyRef:
        name: oracle-secret
        key: DB_USER
  - name: DB_PASSWORD
    valueFrom:
      secretKeyRef:
        name: oracle-secret
        key: DB_PASSWORD
When the container starts, your Struts application will use these production-grade settings.

7. Example Struts Action for Database Check

Use this in a Struts action to verify connectivity:
public class DbCheckAction 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("OracleDB connected successfully!");
      return SUCCESS;
    } catch (Exception e) {
      addActionError("Connection error: " + e.getMessage());
      return ERROR;
    }
  }
}
This code works in both development and production environments.

Why This Method Works

  • Streamlined local dev with Docker and straightforward .properties
  • Secure production deployment using Kubernetes' ConfigMaps and Secrets
  • Unified codebase: no branching logic needed for dev vs. prod
  • Clear environment separation minimizes mistakes and enhances maintainability
By pairing Struts with Docker-local OracleDB and Kubernetes-powered production config, you get a clean, maintainable setup for enterprise-grade Java applications. You’ll enjoy ease of development and secure deployment—all while keeping your config neat and standardized. Now you’re all set to build Oracle-backed web apps with Struts, whether local or in the cloud!

image quote pre code