Class H2DatabaseHelper

java.lang.Object
edu.pdx.cs.joy.jdbc.H2DatabaseHelper

public class H2DatabaseHelper extends Object
Helper class for creating connections to H2 databases. Provides factory methods for both in-memory and file-based H2 databases.
  • Constructor Details

  • Method Details

    • createInMemoryConnection

      public static Connection createInMemoryConnection(String databaseName) throws SQLException
      Creates a connection to an in-memory H2 database. The database will persist as long as at least one connection remains open due to the DB_CLOSE_DELAY=-1 parameter.
      Parameters:
      databaseName - the name of the in-memory database
      Returns:
      a connection to the in-memory H2 database
      Throws:
      SQLException - if a database error occurs
    • createFileBasedConnection

      public static Connection createFileBasedConnection(File databaseFilesDirectory) throws SQLException
      Creates a connection to a file-based H2 database. The database will be persisted to a file at the specified path.
      Parameters:
      databaseFilesDirectory - the database file (without the .mv.db extension)
      Returns:
      a connection to the file-based H2 database
      Throws:
      SQLException - if a database error occurs