Prerequisites
Before you begin, ensure you have the following installed on your system:Java Development Kit
JDK 8 or higher required for JDBC 4.0+ support
Text Editor or IDE
Any Java IDE (IntelliJ IDEA, Eclipse, VS Code) or text editor
Terminal Access
Command line interface for compilation and execution
Internet Connection
For downloading JDBC drivers and dependencies
Step-by-step Installation
The tutorial code is compatible with Java 8 through Java 21. We recommend Java 17 (LTS) for the best experience.
# Download H2 JDBC driver
wget https://repo1.maven.org/maven2/com/h2database/h2/2.2.224/h2-2.2.224.jar
# Or using curl
curl -O https://repo1.maven.org/maven2/com/h2database/h2/2.2.224/h2-2.2.224.jar
Manual download: Visit Maven Central - H2
# Download HSQLDB JDBC driver
wget https://repo1.maven.org/maven2/org/hsqldb/hsqldb/2.7.2/hsqldb-2.7.2.jar
# Or using curl
curl -O https://repo1.maven.org/maven2/org/hsqldb/hsqldb/2.7.2/hsqldb-2.7.2.jar
Manual download: Visit Maven Central - HSQLDB
Store the JAR files in the same directory as your Java source files, or specify the full path in your classpath.
git clone https://github.com/Alepern32/Trabajo_AD_Tarea2.git
cd Trabajo_AD_Tarea2/Acceso_Datos_Tarea2
ContadorBuggy.java
ContadorEnBD.java
ContadorEnBDUpdatable.java
ContadorEnBDsoloUpdateSql.java
ContadorSqlTransaccional.java
ContadorSqlTransaccionalResUpdateable.java
CrearJar.java
DB_Enterprise.java
DB_EnterpriseH2.java
DB_EnterpriseHSQLDB.java
config.ini
EmpresaHSQLDB.jar
h2-2.2.224.jar (if downloaded)
Configuration File
The project includes aconfig.ini file for database configuration:
config.ini
DB_Enterprise.java to determine which database driver to load:
DB_Enterprise.java:22-48
If
config.ini doesn’t exist, the application will create it automatically with default values.Compilation Instructions
Compile for H2 Database
Compile for HSQLDB
Compile Counter Examples
IDE Setup
IntelliJ IDEA
- Open IntelliJ IDEA and create a new Java project
- Copy all
.javafiles to thesrcfolder - Add JDBC driver to project:
- File → Project Structure → Libraries
- Click + and select Java
- Browse to your
h2-2.2.224.jarfile - Click OK
- Right-click
DB_EnterpriseH2.javaand select Run
Eclipse
- Create a new Java project
- Copy all
.javafiles to thesrcfolder - Add JDBC driver to build path:
- Right-click project → Build Path → Configure Build Path
- Select Libraries tab
- Click Add External JARs
- Select your
h2-2.2.224.jarfile
- Right-click
DB_EnterpriseH2.java→ Run As → Java Application
VS Code
- Install the Extension Pack for Java
- Open the project folder in VS Code
- Create a
.vscode/settings.jsonfile: - Press F5 to run with the Java debugger
Maven/Gradle Setup (Optional)
For larger projects, use a build tool:- Maven
- Gradle
Create a Then run:
pom.xml:Verify Installation
Test that everything works:If you see the menu, your installation is successful!
Database Files
After running the applications, you’ll see database files created:H2 Database Files
HSQLDB Files
Troubleshooting
java: command not found
java: command not found
ClassNotFoundException: org.h2.Driver
ClassNotFoundException: org.h2.Driver
The H2 driver JAR is not in the classpath.Solution:
- Ensure
h2-2.2.224.jaris in the current directory - Use the
-cpflag correctly: - On Windows, use semicolon:
-cp ".;h2-2.2.224.jar"
UnsupportedClassVersionError
UnsupportedClassVersionError
Your Java version is too old.Solution:
- Check your Java version:
java -version - Upgrade to Java 8 or higher
- If you compiled with a newer Java, recompile with an older target:
Database file locked error
Database file locked error
Another process is using the database.Solution:
- Close any other instances of the application
- Delete lock files:
- The
AUTO_SERVER=TRUEparameter in the connection URL helps prevent this
Permission denied when creating database files
Permission denied when creating database files
Insufficient file system permissions.Solution:
- Run from a directory where you have write permissions
- Check directory permissions:
Next Steps
Now that you have everything installed:Quickstart Guide
Run your first database application
Database Configuration
Learn about connection settings and config.ini
CRUD Operations
Explore create, read, update, and delete operations
Examples
Try different database implementations