Skip to content
devarentPublic

About

Connect a plain Java 21 application to PostgreSQL and H2 with JDBC, then inspect metadata and run prepared statements.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

jdbc-lab

Connect a plain Java 21 application to PostgreSQL and H2 with JDBC, then inspect metadata and run prepared statements.

At a glance

Field Detail
Repository jdbc-lab
Primary language Java
Topics database, database-labs, devarent, docker, java, jdbc, lab, postgresql, sql
License MIT
Branch main
Maintainer @devarent

Overview

jdbc-lab is a hands-on repository focused on: Connect a plain Java 21 application to PostgreSQL and H2 with JDBC, then inspect metadata and run prepared statements.. Primary language: Java. Topics: database, database-labs, devarent, docker, java, jdbc, lab, postgresql, sql. The README below documents the project; use the table above for a quick overview.

Global references

🇮🇸 Iceland · 🇳🇿 New Zealand · 🇨🇭 Switzerland · 🇸🇮 Slovenia · 🇮🇪 Ireland · 🇦🇹 Austria · 🇵🇹 Portugal · 🇸🇬 Singapore · 🇫🇮 Finland


jdbc-lab LANG Java STARS 0 LICENSE MIT
OPEN SOURCE BUILT IN PUBLIC HANDS ON LABS DOCUMENTED

Connect a plain Java 21 application to PostgreSQL and H2 with JDBC, then inspect metadata and run prepared statements.


Arya Fatthurahman

JDBC Lab

Connect a plain Java 21 application to PostgreSQL and H2 with JDBC, then inspect metadata and run prepared statements.

Database: JDBC Category: Database driver / Java Runs in Docker License: MIT ci

What this lab is

JDBC is the contract between Java applications and relational databases. This lab shows the smallest useful example: one connection, one table, a prepared insert, a query, and the database metadata. It also collects the JDBC URL patterns you need for the other engines in this collection.

Quickstart

docker compose up -d
# requires JDK 21 and Maven 3.9+
mvn -q compile exec:java -Dexec.mainClass=lab.JdbcLab
# or run against H2 without Docker:
JDBC_URL='jdbc:h2:mem:lab;DB_CLOSE_DELAY=-1' JDBC_USER=sa JDBC_PASSWORD='' mvn -q compile exec:java -Dexec.mainClass=lab.JdbcLab

Connection details

Field Value
PostgreSQL URL jdbc:postgresql://localhost:5432/lab
PostgreSQL user lab
PostgreSQL password labpassword
H2 in-memory URL jdbc:h2:mem:lab;DB_CLOSE_DELAY=-1
H2 user sa
H2 password (empty)

Examples

File What it shows
docker-compose.yml Engine, ports, and persistent volume.
.github/workflows/ci.yml Builds the Java project with Maven on every push.
examples/schema.sql Table used by the Java example and by the PostgreSQL container on first start.
src/main/java/lab/JdbcLab.java A complete JDBC workflow: connect, create, insert, query, print metadata.
pom.xml Java 21 build with the PostgreSQL and H2 drivers and the exec plugin.
run.ps1 Windows helper. Starts nothing; run docker compose up -d first.
run.sh Linux/macOS helper. Starts nothing; run docker compose up -d first.

Exercises

  1. Change JDBC_URL to the H2 URL and run the same code without PostgreSQL.
  2. Print DatabaseMetaData.getDriverName() and getJDBCMajorVersion().
  3. Use addBatch() and executeBatch() to insert 100 rows in one round trip.
  4. Try a wrong password and catch SQLException, printing the SQLState and vendor code.

Notes and limits

  • Requires JDK 21 and Maven 3.9+. The CI workflow builds with mvn -B -q -DskipTests package.
  • The PostgreSQL container creates the lab_notes table on first start from examples/schema.sql.
  • JDBC URL patterns for other engines are listed in the README table below.
  • This is a local lab. Do not use these credentials anywhere public.

Run it from anywhere

This lab publishes its ports on 127.0.0.1 only. To use it from another country, do not open the database port to the internet. Pick one:

  • VPS + private tunnel: run the lab on a small Ubuntu VPS, keep the port closed, and connect through WireGuard or ssh -L.
  • Managed service: use a managed free tier for this engine and point the same examples at its connection string.
  • HTTP UI only: if the engine has a web UI, put it behind Caddy with TLS and basic auth.

The shared checklist, provider map, and commands are in REMOTE-ACCESS.md.

Cleanup

docker compose down -v

-v also removes the named volume, so the next start is a clean slate.

References


Part of the database-labs collection: 26 database engines, one index.

License

MIT (c) 2026 Arya Fatthurahman. See LICENSE.


Tech Stack

Git
Full Tech Stack Wall

Languages
Rust Go TypeScript JavaScript Java Python C C++ Kotlin Swift Ruby PHP Lua Shell

Frontend & Desktop
Vue React Svelte Next.js Nuxt Flutter React Native Tauri Electron Vite HTML5 CSS3 Sass Less Tailwind CSS Bootstrap Three.js Node.js jQuery

Database & Storage
MySQL PostgreSQL SQLite SQL Server Oracle Redis MongoDB DuckDB ClickHouse Elasticsearch Neo4j InfluxDB Cassandra DynamoDB Firebase Supabase MinIO Firebird IBM DB2 MariaDB CockroachDB IRIS Databricks SQL Snowflake Qdrant Redshift Apache Kylin BigQuery VictoriaMetrics Databend TDengine Teradata

Messaging & Streaming
Kafka RabbitMQ RocketMQ Pulsar Flink

DevOps & Cloud Native
Docker Kubernetes Terraform Ansible Jenkins GitHub Actions GitLab CI Prometheus Grafana Nginx AWS Azure Cloudflare

Tools & Platforms
Git Linux macOS VS Code Vim Tmux Homebrew Postman Figma Markdown Maven Gradle CMake

Hands-on engineering, built and documented in the open.

DBX Connections

Firebird_5n1b JDBCX_d5pn IBM DB2_0leg MariaDB_80g9 SQL Server_wieh CockroachDB_mo9c IRIS_cz3h Databricks_SQL_rmue Snowflake_cm_h9 Redis_u0tv Qdrant_1r3s Elasticsearch_zfc3 Cassandra_d8eb MongoDB_vexq Redshift_p9d7 Apache Kylin_xmpz Neo4j_j3dsg BigQuery_homk Apache Kafka_xpqk VictoriaMetrics_m3sf InfluxDB_wuju Databend_dey6 TDengine_4c9i Teradata_rwlm

Connection names shown in the DBX sidebar - decorative reference badges.

About

Connect a plain Java 21 application to PostgreSQL and H2 with JDBC, then inspect metadata and run prepared statements.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages