| name | json/jdbc-json-basic | |||||
|---|---|---|---|---|---|---|
| description | Plain JDBC sample for inserting, querying, updating, and deleting Oracle JSON data. | |||||
| tags |
|
|||||
| blog_post | https://andersswanson.dev/2026/02/24/hands-on-crud-with-jdbc-and-json-relational-duality-views/ |
This sample demonstrates how to interact with the Oracle JSON data type using plain JDBC. A console-style program inserts, queries, updates, and deletes JSON documents stored in a relational table while leveraging SQL/JSON operators like json_value and json_transform.
- Bind JSON payloads as
VARCHAR2/SQL JSON and hydrate them back into Jakarta JSONJsonObjectinstances. - Filter documents by attributes with
json_valueand apply in-place updates viajson_transform. - Exercise the complete insert/read/update/delete lifecycle against a JSON column backed by Oracle AI Database Free.
- Validate the flow with a Testcontainers-powered integration test that provisions a fresh database for each run.
- Java 21+
- Maven 3.9+
- Docker Desktop or another OCI-compatible container runtime (required for the Testcontainers test)
From the repository root:
mvn compile exec:java -Dexec.args="jdbc:oracle:thin:@localhost:1521/freepdb1 testuser testpwd"The program will insert a JSON document describing a product, fetch it back, update its price, query similar products by category, and delete the record.
docker pull gvenzl/oracle-free:23.26.1-slim-faststart
mvn testJsonAttributesSampleTest starts Oracle AI Database Free in a container, runs the CRUD scenario, and tears down the database afterwards.