Package edu.ntnu.stud.model.database
Class DbLink
java.lang.Object
edu.ntnu.stud.model.database.DbLink
This class provides a connection to the database.
Mention being written by Surya.
We do have additions though: the getConnectionNoDB method was not in Surya's code.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
close
(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet) Closes connections to database, makes sure that resultSets and statements gets closed properly.Returns a connection to the database.getConnectionNoDB
(String dbName) Returns a connection to the database without specifying a database.static DbLink
instance()
Returns the instance of the database connection provider.
-
Constructor Details
-
DbLink
public DbLink()Constructor for the DbLink class. Creates a connection to the database. -
DbLink
Constructor for the DbLink class. Creates a connection to the database with the given parameters.- Parameters:
url
- The URL to the database.username
- The username to the database.password
- The password to the database.
-
-
Method Details
-
instance
Returns the instance of the database connection provider.- Returns:
- The instance of the database connection provider.
-
close
public static void close(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet) Closes connections to database, makes sure that resultSets and statements gets closed properly.- Parameters:
connection
- the connection to be closedpreparedStatement
- the preparedStatement to be closedresultSet
- the resultSet to be closed
-
getConnection
Returns a connection to the database.- Returns:
- A connection to the database.
- Throws:
DbConnectionErrorException
- If an error occurs while connecting to the database.
-
getConnectionNoDB
Returns a connection to the database without specifying a database.- Parameters:
dbName
- The name of the database to connect to.- Returns:
- A connection to the database.
- Throws:
DbConnectionErrorException
- If an error occurs while connecting to the database.
-