Table of Contents
- Overview
- Configuring a connection
- How it integrates with EXEC SQL
- When your changes commit or roll back
- A quick checklist
- Summary
- Related articles
Audience: developers and operations engineers running PL/I programs that use EXEC SQL, migrated to Java with Heirloom.
Overview
PL/I programs that use EXEC SQL keep their embedded SQL after migration. The Heirloom PL/I Runtime implements the SQL layer directly and connects to your database — typically DB2 — through standard JDBC. Your job is to tell the runtime how to reach the database; the SQL statements themselves are unchanged.
This article covers connection configuration (including credentials), how the runtime runs your EXEC SQL, and when your changes are committed or rolled back.
Note: All URLs, datasource names, and credentials below are examples. Replace them with your own. Never commit real credentials to source control — supply them through a secured datasource or properties file at deploy time.
Configuring a connection
Connections live in the sql.<connection>.* property namespace. The implicit connection is named default — what an ordinary EXEC SQL statement uses unless told otherwise.
You connect in one of two ways: a direct JDBC URL (with driver + credentials), or a container datasource (JNDI). Use one or the other.
| Property | Example | Purpose |
|---|---|---|
sql.<conn>.url |
jdbc:db2://db2host:50000/MYDB |
JDBC URL of the database |
sql.<conn>.driver |
com.ibm.db2.jcc.DB2Driver |
JDBC driver class (used with a URL) |
sql.<conn>.user |
<db-user> |
Database username (used with a URL) |
sql.<conn>.password |
<db-password> |
Database password (used with a URL) |
sql.<conn>.datasource |
jdbc/MyDataSource |
A container datasource (JNDI) — alternative to URL + driver + credentials |
sql.<conn>.autocommit |
false |
false = statements form one unit of work (recommended); true = each statement commits immediately |
sql.<conn>.isolation |
committed |
Isolation level: uncommitted / committed / repeatable / serializable
|
sql.<conn>.readonly |
false |
Mark the connection read-only |
sql.xa.datasource |
true |
Use an XA datasource so the database can join a global (two-phase-commit) transaction with other resources |
sql.log |
true |
Write SQL activity to the server log (diagnostics) |
A typical default connection using a container datasource (credentials managed by the server, so the URL/driver/user/password lines are not needed):
sql.default.autocommit=false
sql.default.datasource=jdbc/MyDataSource
sql.default.isolation=committed
sql.default.readonly=false
sql.xa.datasource=true
sql.log=true
#sql.default.url=jdbc:db2://db2host:50000/MYDB
#sql.default.driver=com.ibm.db2.jcc.DB2Driver
#sql.default.user=<db-user>
#sql.default.password=<db-password>
To connect with a direct URL and credentials instead of a datasource, set the commented lines and drop the datasource:
sql.default.url=jdbc:db2://db2host:50000/MYDB
sql.default.driver=com.ibm.db2.jcc.DB2Driver
sql.default.user=<db-user>
sql.default.password=<db-password>
sql.default.autocommit=false
sql.default.isolation=committed
Datasource vs. URL: prefer a container datasource on an application server — it pools connections and keeps credentials in the server, not the application. The direct URL form is handy for standalone/batch or local testing.
Named connections (multiple databases)
To target more than one database, configure additional named connections and have the program select one. Each name gets its own sql.<name>.* block:
sql.default.datasource = jdbc/PrimaryDb
sql.reporting.datasource = jdbc/ReportingDb
How it integrates with EXEC SQL
The runtime translates each EXEC SQL statement into JDBC against the configured connection — SELECT / INSERT / UPDATE / DELETE / MERGE, cursors (DECLARE / OPEN / FETCH / CLOSE, which map to JDBC result sets), stored procedure CALL, and dynamic SQL. After each statement the standard SQLCA feedback (SQLCODE / SQLSTATE) is set, exactly as your program expects. The connection is shared for the program's unit of work, and cursors are released when the program completes. (For the full statement list, see Supported SQL Features.)
When your changes commit or roll back
This is the most important behavior to get right. With the recommended setting autocommit=false, each statement is part of a unit of work — nothing is saved on its own. The work is then resolved as follows:
Committed (saved) on success — two ways:
-
With
SYNCPOINT: when the program issuesEXEC CICS SYNCPOINT, the unit of work is committed at that point — your SQL changes and any other transactional resources (e.g. MQ messages put under syncpoint) commit together. -
Without
SYNCPOINT: if the program never issues an explicit syncpoint, the accumulated SQL work is committed implicitly at the normal, successful end of the transaction.
Rolled back (discarded) on failure — two ways:
-
With
SYNCPOINT ROLLBACK:EXEC CICS SYNCPOINT ROLLBACKexplicitly discards the work done since the last commit. - On ABEND: if the transaction ends abnormally, the unit of work is rolled back automatically — nothing is saved.
So the rule of thumb: success → commit (at SYNCPOINT, or at the end if none); ABEND → rollback. Because SQL joins the unit of work, it always commits or rolls back atomically with the transaction's other resources. With an XA datasource (sql.xa.datasource=true), DB2 participates in a global two-phase commit coordinated by the transaction manager, keeping the database and other XA resources consistent.
autocommit=truechanges this. Each statement then commits immediately andSYNCPOINT/ rollback no longer governs your SQL. Only use it when you truly want per-statement commit (rarely, for transactional programs).
A quick checklist
- Choose a datasource (
sql.default.datasource) or a URL (sql.default.url+driver+user+password). - Keep
sql.default.autocommit=falseso statements form a proper unit of work. - Set
sql.default.isolationto match your application's needs (committedis typical). - Use
sql.xa.datasource=truewhen the database must commit atomically with MQ / other resources. - Confirm the DB2 JDBC driver is on the runtime classpath.
- Supply credentials via the datasource or a secured properties file — never in source.
Summary
- The runtime implements SQL over JDBC; your
EXEC SQLis unchanged. - Configure connections under
sql.<connection>.*(defaultis implicit) — a datasource, or a URL withdriver+user/password. - Keep
autocommit=falseso work forms a unit of work; use an XA datasource to commit atomically with other resources. -
Success commits (explicitly at
SYNCPOINT, or implicitly at transaction end); ABEND /SYNCPOINT ROLLBACKrolls back.
Related articles
- How Transactions Are Managed (ETP + PL/I Runtime) — the transaction boundary behind commit/rollback.
- Supported SQL Features — the embedded-SQL statements supported.
- How to Use IBM MQ Messaging — MQ work that commits in the same unit of work.
0 Comments