Class Database

java.lang.Object
persistence.db.Database

public final class Database extends Object
Class that initializes and connects to the generated database.
  • Field Details

  • Constructor Details

    • Database

      public Database()
  • Method Details

    • getConnection

      public static Connection getConnection() throws SQLException
      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.