Package no.ntnu.idatt1002.demo.dao
Class DBConnectionProvider
java.lang.Object
no.ntnu.idatt1002.demo.dao.DBConnectionProvider
This class provides a connection to the database.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static DBConnectionProviderprivate static Stringprivate final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcloseConnection(Connection connection) This method closes the connection to the database.voidclosePreparedStatement(PreparedStatement preparedStatement) This method closes the PreparedStatement.voidcloseResultSet(ResultSet resultSet) This method closes the ResultSet.Gets a connection to the database.static DBConnectionProviderGets the instance of the DBConnectionProvider.static voidSets the path to the database.
-
Field Details
-
url
-
databaseConnectionProvider
-
DB_PATH
-
-
Constructor Details
-
DBConnectionProvider
public DBConnectionProvider()Constructor for the DBConnectionProvider class.
-
-
Method Details
-
setDbPath
Sets the path to the database. Mainly used for testing purposes.- Parameters:
dbPath- the path to the database
-
getConnection
Gets a connection to the database.- Returns:
- a connection to the database
-
getInstance
Gets the instance of the DBConnectionProvider.- Returns:
- the instance of the DBConnectionProvider
-
closeConnection
This method closes the connection to the database.- Parameters:
connection- the connection to the database
-
closePreparedStatement
This method closes the PreparedStatement.- Parameters:
preparedStatement- the PreparedStatement
-
closeResultSet
This method closes the ResultSet.- Parameters:
resultSet- the ResultSet
-