Skip to main content

Welcome to Database Access Tutorial

This educational project demonstrates essential JDBC database operations through practical, real-world examples. You’ll learn how to work with embedded databases, manage transactions, handle concurrency, and build complete CRUD applications in Java.

Quick Start

Get up and running with your first database application in minutes

Installation

Set up your development environment with Java and database drivers

CRUD Operations

Master create, read, update, and delete operations

Examples

Explore complete working examples with HSQLDB and H2

Key Features

Dual Database Support

Work with both HSQLDB and H2 embedded databases with identical schemas

Transaction Management

Learn proper transaction handling with commit, rollback, and isolation levels

Concurrency Patterns

Understand race conditions and atomic operations through counter examples

Enterprise Schema

Practice with a realistic employee management system including centers, departments, and employees

Configuration Management

External configuration via properties files for flexible deployment

JAR Deployment

Package applications as portable JAR files for easy distribution

What You’ll Learn

  • Establishing database connections with DriverManager
  • Using PreparedStatement for parameterized queries
  • ResultSet navigation and data retrieval
  • Resource management with try-with-resources
  • setAutoCommit() for manual transaction control
  • commit() and rollback() operations
  • FOR UPDATE row locking
  • Isolation levels and deadlock prevention
  • Foreign key relationships
  • Primary key constraints
  • Data type selection (INTEGER, VARCHAR, DATE, DECIMAL)
  • Referential integrity
  • Connection pooling considerations
  • Error handling and exception management
  • Updatable ResultSets vs. SQL UPDATE statements
  • Configuration externalization

Project Structure

The project includes several focused examples:
  • DB_Enterprise - Configuration-driven database connection setup
  • DB_EnterpriseHSQLDB - Complete employee management system with HSQLDB
  • DB_EnterpriseH2 - Complete employee management system with H2
  • Counter Implementations - Various approaches to thread-safe counter operations
  • CrearJar - Utility for packaging applications as executable JARs

Database Schema

The enterprise management examples use a three-table schema:
t_centros (Centers)
├── codigo_centro (PK)
├── nombre_centro
└── ubicacion

t_departamentos (Departments)
├── codigo_departamento (PK)
├── codigo_centro (FK → t_centros)
├── codigo_director
├── tipo_director
├── presupuesto_departamento
├── codigo_departamento_superior
└── nombre_departamento

t_empleados (Employees)
├── codigo_empleado (PK)
├── codigo_departamento (FK → t_departamentos)
├── extension_telefonica_empleado
├── fecha_nacimiento_empleado
├── fecha_ingreso_empleado
├── salario_base_empleado
├── comision_empleado
├── numero_hijos_empleado
└── nombre_empleado

Getting Started

1

Install Java

Ensure you have Java 8 or higher installed on your system
2

Get the Code

Clone the repository from GitHub
3

Run an Example

Compile and run DB_EnterpriseH2.java to see the employee management system in action
This is an educational project designed for learning JDBC concepts. The examples prioritize clarity and demonstration of specific patterns over production-ready architecture.

Next Steps

Follow the Quickstart

Run your first example and explore the interactive menu

Explore Components

Learn about configuration management and database connections

Build docs developers (and LLMs) love