java.lang.Object
com.example.cab302project.SqliteConnection
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 Summary
-
Method Details
-
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
Connectionto 'data.db'; returns null if a connection could not be established.
-