Class Database
java.lang.Object
persistence.db.Database
Class that initializes and connects to the generated database.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ConnectionMethods that provides a connection the URL/file that is initialized.static voidMethod that initializes/creates the database.
-
Field Details
-
URL
- See Also:
-
-
Constructor Details
-
Database
public Database()
-
-
Method Details
-
getConnection
Methods that provides a connection the URL/file that is initialized. Runs "PRAGMA FOREIGN KEYS = ON", which turns foreign key check on in SQLite. Connection class is used to connect the java-code to the database/SQL-code.- Returns:
- returns connection to database.
- Throws:
SQLException
-
initializeDatabase
public static void initializeDatabase()Method that initializes/creates the database. Uses file "schema.sql" to create, which contains SQL-code that creates the tables. Splits string at ";", to separate each CREATE TABLE-sentences.- Throws:
RuntimeException- if the schema file cannot be read or a database error occurs.
-