Class DatabaseUtils

java.lang.Object
io.github.the_sdet.db.DatabaseUtils

public class DatabaseUtils extends Object
This is a utility class to handle all the database querying operations needed for validations against database
Author:
Pabitra Swain ([email protected])
  • Constructor Details

    • DatabaseUtils

      public DatabaseUtils(Connection connection)
      Initializes Database utils
      Parameters:
      connection - JDBC Connection Object
  • Method Details

    • closeDatabaseConnection

      public void closeDatabaseConnection()
      This method closes the established Database connection
    • readDataFromDbWithColumnNames

      public List<LinkedHashMap<String,String>> readDataFromDbWithColumnNames(String sql)
      This method executes an SQL query and returns the result with the column names
      Parameters:
      sql - sql statement to query the DB
      Returns:
      A list of rows are returned where each row is returned as a LinkedHashMap
    • readDataFromDb

      public List<List<String>> readDataFromDb(String sql)
      This method executes an SQL query and returns the result without the column names
      Parameters:
      sql - sql statement to query the DB
      Returns:
      A list of rows are returned where each row is returned as a List
    • readSingleRowFromDbWithColumnNames

      public LinkedHashMap<String,String> readSingleRowFromDbWithColumnNames(String sql)
      This method executes an SQL query and returns only the first row with the column names
      Parameters:
      sql - sql statement to query the DB
      Returns:
      Only one row is returned as a LinkedHashMap
    • readSingleRowFromDb

      public List<String> readSingleRowFromDb(String sql)
      This method executes an SQL query and returns only the first row without the column names
      Parameters:
      sql - sql statement to query the DB
      Returns:
      Only one row is returned as a List
    • readSingleDataFromDb

      public String readSingleDataFromDb(String sql)
      This method executes an SQL query and returns only the data at first position of first row as a String
      Parameters:
      sql - sql statement to query the DB
      Returns:
      Single String value from position [0][0]
    • readSingleColumnFromDb

      public List<String> readSingleColumnFromDb(String sql)
      This method executes an SQL query and returns the first column data without the column names
      Parameters:
      sql - sql statement to query the DB
      Returns:
      First column data is returned as a List