Class DbLink

java.lang.Object
edu.ntnu.stud.model.database.DbLink

public class DbLink extends Object
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 Details

    • DbLink

      public DbLink()
      Constructor for the DbLink class. Creates a connection to the database.
    • DbLink

      public DbLink(String url, String urlNoDb, String username, String password)
      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

      public static DbLink 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 closed
      preparedStatement - the preparedStatement to be closed
      resultSet - the resultSet to be closed
    • getConnection

      public Connection getConnection() throws DbConnectionErrorException
      Returns a connection to the database.
      Returns:
      A connection to the database.
      Throws:
      DbConnectionErrorException - If an error occurs while connecting to the database.
    • getConnectionNoDB

      public Connection getConnectionNoDB(String dbName) throws DbConnectionErrorException
      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.