Package storage
Class DatabaseConnection
java.lang.Object
storage.DatabaseConnection
Singleton class for managing database connections to MySQL
Ensures only one instance exists and provides connection pooling
- Author:
- TAMIL MUGHILAN
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Private constructor to prevent direct instantiation. -
Method Summary
Modifier and TypeMethodDescriptionCreates and returns a new database connection.static DatabaseConnection
Gets the singleton instance of DatabaseConnection.
-
Field Details
-
instance
-
url
- See Also:
-
USER
- See Also:
-
PASSWORD
- See Also:
-
-
Constructor Details
-
DatabaseConnection
Private constructor to prevent direct instantiation. Loads MySQL JDBC driver when instance is created.- Throws:
SQLException
- if JDBC driver is not found
-
-
Method Details
-
getInstance
Gets the singleton instance of DatabaseConnection. Uses double-checked locking for thread safety.- Returns:
- the singleton DatabaseConnection instance
- Throws:
SQLException
- if instance creation fails
-
getConnection
Creates and returns a new database connection.- Returns:
- a new Connection object to the database
- Throws:
SQLException
- if connection fails
-