Explain how Java integrates with Oracle Database 23c/23ai and OCI, and when to use PL/SQL vs. Java.
Java and Oracle in the 23c/23ai Era
Oracle gave DBAs two broad integration models for Java: inside the database (embedded JVM for stored Java) and outside the database (application servers or services that connect over the network). In 23c/23ai and OCI, the external, service-based model is the strategic default, while the embedded JVM remains supported for niche use cases.
Are Java apps with JDBC still used on OCI?
Yes. Java applications that use JDBC are standard on Oracle Cloud Infrastructure (OCI). Typical patterns include:
Autonomous Database (ATP/AJD/Apex): Apps connect with the thin driver using TLS and TNS_ADMIN wallet or mTLS credentials. Use UCP or HikariCP for pooling; enable DRCP on the database side for massive concurrency.
Base Database on OCI: Connect via private endpoints within a VCN; secure with TLS, SCAN listeners for RAC, and Network Security Groups (NSGs).
Alternatives when Java isn’t required: ORDS (REST), Python/Node/Go drivers, or microservices that call ORDS endpoints. These coexist with (not replace) JDBC.
When to use PL/SQL vs. Java
PL/SQL (preferred in-database logic): Set-based data access, constraints, auditing, and transactional business rules.
Java (in the app tier): Web/API layers, orchestration, integration, streaming, and CPU-bound libraries (ML clients, PDF/Office tooling).
Java (inside DB, niche): Where you must run a Java library next to data and can sandbox it (e.g., specialized parsing). Keep footprint small; prefer PL/SQL for data logic.
Historical view (Oracle8i): stored Java/PLSQL in one engine. Modern guidance: keep most business logic in PL/SQL or in external services; use stored Java only when necessary.JDBC remains the primary Java interface to Oracle. Today, use the thin driver, TLS, wallets/mTLS, and UCP/DRCP for scale.Modern scalability is achieved via app-tier pooling (UCP/HikariCP), database-tier pooling (DRCP), RAC/Exadata, and OCI private endpoints.
Modern Java ↔ Oracle patterns
JDBC Thin + UCP: Default for Java apps on OCI and on-prem.
DRCP: Server-side session pooling for high connection counts (serverless/functions/microservices).
ORDS: Expose SQL/PLSQL and JSON relational duality as REST APIs for polyglot clients.
Security: TLS 1.2/1.3, wallets (or mTLS), least-privilege DB roles, and private subnets/NSGs.
// Java 17+/22, JDBC Thin, UCP, ATP with wallet
import java.sql.*;
import oracle.ucp.jdbc.PoolDataSource;
import oracle.ucp.jdbc.PoolDataSourceFactory;
PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource();
pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
pds.setURL("jdbc:oracle:thin:@adb_high?TNS_ADMIN=/path/to/wallet");
pds.setUser("APPUSER");
pds.setPassword(System.getenv("APP_DB_PASSWORD"));
pds.setMinPoolSize(1);
pds.setMaxPoolSize(50);
pds.setValidateConnectionOnBorrow(true);
// Optional: DRCP
pds.setConnectionProperty("oracle.jdbc.DRCPConnectionClass","appPool");
// Use try-with-resources per request
try (Connection conn = pds.getConnection();
PreparedStatement ps = conn.prepareStatement(
"select product_id, name from products where price > ?")) {
ps.setBigDecimal(1, new java.math.BigDecimal("1000"));
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
// consume rows
}
}
}
Design notes and anti-patterns
Avoid applets and in-browser JVMs: obsolete and insecure.
Prefer set-based logic: Don’t pull large result sets just to loop in Java; push compute into SQL/PLSQL where feasible.
Keep stored Java small: Only when PL/SQL cannot do the job and you need the code next to data.
Where Java shines with 23c/23ai features
JSON/Relational Duality: Combine JSON docs with relational queries via JDBC.
AI Vector Search: Store/query VECTOR embeddings; call ML services from the app tier and persist vectors in Oracle.
Microservices on OCI: Java services (Micronaut/Quarkus/Spring) in OKE/Functions connect to Autonomous DB with UCP+DRCP.
Summary
JDBC-based Java applications are alive and well on OCI. Use the thin driver with TLS and wallets, pool connections in the app (UCP/HikariCP), optionally enable DRCP, and push set-based work to SQL/PLSQL. Treat stored Java as a niche tool; prefer external services and ORDS for REST access. This approach yields the best performance, security, and operability in Oracle 23c/23ai.