Package io.github.the_sdet.db
Class DatabaseUtils
java.lang.Object
io.github.the_sdet.db.DatabaseUtils
This is a utility class to handle all the database querying operations needed
for validations against database
- Author:
- Pabitra Swain ([email protected])
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThis method closes the established Database connectionreadDataFromDb(String sql) This method executes an SQL query and returns the result without the column namesThis method executes an SQL query and returns the result with the column namesThis method executes an SQL query and returns the first column data without the column namesThis method executes an SQL query and returns only the data at first position of first row as a StringThis method executes an SQL query and returns only the first row without the column namesThis method executes an SQL query and returns only the first row with the column names
-
Constructor Details
-
DatabaseUtils
Initializes Database utils- Parameters:
connection- JDBC Connection Object
-
-
Method Details
-
closeDatabaseConnection
public void closeDatabaseConnection()This method closes the established Database connection -
readDataFromDbWithColumnNames
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
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
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
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
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
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
-