Class SqliteConnection

java.lang.Object
com.example.cab302project.SqliteConnection

public class SqliteConnection extends Object
Manages a single, shared connection to the SQLite database. This class implements a thread-safe Singleton pattern to ensure that the application maintains only one active connection to the database file at any time, preventing file-locking issues.
  • Method Details

    • getInstance

      public static Connection getInstance()
      Retrieves the active database connection. If the connection does not exist or has been closed, a new one is established.

      The method is synchronized to ensure that multiple threads (e.g., background tasks) do not attempt to open separate connections simultaneously.

      Returns:
      The active Connection to 'data.db'; returns null if a connection could not be established.