Package edu.pdx.cs.joy.jdbc
Class H2DatabaseHelper
java.lang.Object
edu.pdx.cs.joy.jdbc.H2DatabaseHelper
Helper class for creating connections to H2 databases.
Provides factory methods for both in-memory and file-based H2 databases.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ConnectioncreateFileBasedConnection(File databaseFilesDirectory) Creates a connection to a file-based H2 database.static ConnectioncreateInMemoryConnection(String databaseName) Creates a connection to an in-memory H2 database.
-
Constructor Details
-
H2DatabaseHelper
public H2DatabaseHelper()
-
-
Method Details
-
createInMemoryConnection
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
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
-