Class H2Initialization

java.lang.Object
lt.viko.eif.jguscia.services.H2Initialization

public class H2Initialization extends Object
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 Details

  • Constructor Details

    • H2Initialization

      public H2Initialization()
  • Method Details

    • getConnection

      public Connection getConnection() throws SQLException
      Creates and returns a new connection to the H2 database.
      Returns:
      active database connection
      Throws:
      SQLException - if a connection cannot be established
    • initSchema

      public void initSchema() throws SQLException
      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