You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5bd4520
Browse filesBrowse the repository at this point in the historyBrowse files
|`EnableSession`|`false`| Enables multi-statement session creation and transaction support (`BEGIN`, `COMMIT`, `ROLLBACK`). |
209
+
|`EnableSession`|`false`| Enables BigQuery multi-statement session creation and transaction support (`BEGIN`, `COMMIT`, `ROLLBACK`). |
210
+
|`QueryProperties`|`null`| Comma- or semicolon-separated key-value pairs passed as connection-level job properties (e.g., `QueryProperties=session_id=<session_id>` to connect to a pre-existing session). |
209
211
210
212
### Data Types & Extended Precision Properties
211
213
@@ -313,58 +315,26 @@ When running queries through the JDBC driver for BigQuery, data types map as spe
313
315
314
316
## 6.JDBCDriverArchitecture&CoreFeatures
315
317
316
-
### TransactionManagement&Multi-StatementSessions
318
+
### Multi-StatementSessions&TransactionManagement
317
319
318
-
BigQuery supports **Multi-StatementTransactions** across tables using standard SQL primitives (`BEGINTRANSACTION`, `COMMITTRANSACTION`, `ROLLBACKTRANSACTION`).The driver bridges standard JDBC methods (`setAutoCommit`, `commit`, `rollback`) directly to BigQuery's underlying session engine.
320
+
BigQuery supports **Multi-StatementSessions**, which preserve state across multiple SQL statements executed on the same connection.
319
321
320
-
#### Session Lifecycle Flow:
322
+
1.**EnablingSessions (`EnableSession=true`)**:
323
+
-Add `;EnableSession=true` (or `EnableSession=1`) to the JDBC connection URL or DataSource properties.
324
+
-Underdefault auto-commit mode (`autoCommit=true`), statements execute and commit individually while sharing session state.
321
325
322
-
```
323
-
[DriverManager.getConnection()]
324
-
│
325
-
(EnableSession=true)
326
-
│
327
-
┌──────────▼──────────┐
328
-
│ setAutoCommit(false)│ ──────► Begins transaction block in session
329
-
└──────────┬──────────┘
330
-
│
331
-
┌──────────▼──────────┐
332
-
│ Execute DML & SQL │ ──────► Runs queries within active session
333
-
│ Statements │
334
-
└──────────┬──────────┘
335
-
│
336
-
┌───────┴───────┐
337
-
│ │
338
-
▼ ▼
339
-
┌─────────┐ ┌──────────┐
340
-
│commit() │ │rollback()│
341
-
└────┬────┘ └────┬─────┘
342
-
│ │
343
-
▼ ▼
344
-
Executes: Executes:
345
-
COMMIT ROLLBACK
346
-
TRANSACTION; TRANSACTION;
347
-
│ │
348
-
└───────┬───────┘
349
-
│
350
-
▼
351
-
(Auto-re-executes BEGIN TRANSACTION; if setAutoCommit remains false)
-Multi-statement transactions require `;EnableSession=true` (calling `setAutoCommit(false)`, `commit()`, or `rollback()` with sessions disabled throws an exception).
328
+
-Calling `conn.setAutoCommit(false)` begins a multi-statement transaction in BigQuery. Statements executed within the transaction block remain uncommitted until `conn.commit()` is explicitly called (or discarded via `conn.rollback()`).
329
+
-If `autoCommit` remains `false`, the driver automatically starts the next transaction block for subsequent statements.
1. **Pre-requisite Check**: Calling `setAutoCommit(false)`, `commit()`, or `rollback()` requires `;EnableSession=true` in the connection URL. If disabled or invoked without an active transaction, an exception is thrown by the driver.
355
-
2. **Session & Transaction Start**:
356
-
- `setAutoCommit(false)` initiates a multi-statement transaction session in BigQuery.
357
-
3. **Statement Propagation**:
358
-
- All `Statement` or `PreparedStatement` instances created on the connection execute within the scope of the active session.
359
-
4. **Commit & Rollback**:
360
-
- `commit()` executes `COMMIT TRANSACTION;` to commit changes.
361
-
- `rollback()` executes `ROLLBACK TRANSACTION;` to discard changes.
362
-
- If `autoCommit` remains `false`, the driver automatically starts the next transaction block.
363
-
5. **Connection Close Safety**:
364
-
- If an uncommitted transaction is pending when `conn.close()` is invoked, the driver automatically rolls back the transaction to prevent uncommitted changes from persisting.
// Query tables or temporary objects in the pre-existing session
396
+
try (ResultSet rs = stmt.executeQuery("SELECT * FROM ExistingTempTable")) {
397
+
while (rs.next()) {
398
+
// Process rows...
399
+
}
400
+
}
401
+
}
402
+
```
403
+
404
+
---
405
+
414
406
### PreparedStatements&ParameterBinding
415
407
Use `PreparedStatement` to safely bind parameters including primitive types, decimals (`BigDecimal`), temporal values (`Date`, `Timestamp`), and byte arrays (`byte[]`).
0 commit comments