Class H2Initialization
java.lang.Object
lt.viko.eif.jguscia.services.H2Initialization
Initializes and manages the in-memory H2 database used by the application.
This class provides a method for obtaining database connections and ensures that the required database schema is created before use.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates and returns a new connection to the H2 database.voidInitializes the database schema.
-
Field Details
-
JDBC_URL
-
USER
-
PASS
-
-
Constructor Details
-
H2Initialization
public H2Initialization()
-
-
Method Details
-
getConnection
Creates and returns a new connection to the H2 database.- Returns:
- active database connection
- Throws:
SQLException- if a connection cannot be established
-
initSchema
Initializes the database schema.<p>Creates the required tables if they do not already exist:<ul><li><b>books</b>– stores book identifiers and titles</li><li><b>book_genres</b>– stores genres associated with each</li></ul>- Throws:
SQLException- if an error occurs while executing SQL statements
-