Overview
The Enterprise Management System provides a complete menu-driven interface for managing an organizational database with three core tables: Centers (Centros), Departments (Departamentos), and Employees (Empleados). Both HSQLDB and H2 implementations offer identical functionality with minor syntax differences.Database Schema
The system manages a hierarchical enterprise structure:Database Initialization
The system automatically creates the complete schema with sample data on first run:- Table Creation
- Sample Data - Centers
- Sample Data - Departments
- Sample Data - Employees
DB_EnterpriseHSQLDB.java:62-96
The initialization checks if tables exist using
DatabaseMetaData to avoid recreating existing databases.Main Menu System
The application provides an interactive menu with seven operations:DB_EnterpriseHSQLDB.java:124-153
CRUD Operations
View Employees (READ with JOIN)
Displays all employees with their department information:DB_EnterpriseHSQLDB.java:155-174
Add Employee (CREATE)
Interactive employee creation with parameterized queries:DB_EnterpriseHSQLDB.java:176-212
Why PreparedStatement?
Why PreparedStatement?
PreparedStatements prevent SQL injection attacks by separating SQL structure from data. Parameters are properly escaped and validated by the database driver.
Search Employees (READ with LIKE)
Pattern-matching search using wildcards:DB_EnterpriseHSQLDB.java:214-236
Delete Employee (DELETE)
Delete operation with confirmation feedback:DB_EnterpriseHSQLDB.java:293-315
Advanced JOIN Operations
The system demonstrates complex multi-table JOINs to combine data from all three tables:DB_EnterpriseHSQLDB.java:256-291
This query performs two INNER JOINs to combine employee, department, and center data in a single result set.
Key Design Patterns
Try-with-Resources
All database operations use try-with-resources to ensure automatic resource cleanup, preventing connection leaks.
PreparedStatements
User input is always handled through PreparedStatements with parameter binding to prevent SQL injection.
Error Handling
Each operation includes SQLException handling with user-friendly error messages while preserving stack traces for debugging.
Menu-Driven Interface
The infinite loop menu pattern with switch-case provides intuitive navigation and operation selection.
HSQLDB vs H2 Differences
Both implementations are nearly identical, with minor differences:| Aspect | HSQLDB | H2 |
|---|---|---|
| DROP IF EXISTS Syntax | DROP TABLE t_empleados IF EXISTS | Same |
| File Cleanup | No automatic cleanup | Explicit file deletion in eliminarArchivosBD() |
| Menu Title | ”=== GESTIÓN EMPRESA ===" | "=== GESTIÓN EMPRESA (H2) ===“ |
| Driver Loading | org.hsqldb.jdbc.JDBCDriver | org.h2.Driver |
Complete Application Flow
Running the Application
Next Steps
Explore related topics:- Database Configuration - Configuration patterns and best practices
- Counter Implementations - Concurrency and atomic operations