Package com.shaft.db

Class DatabaseActions

java.lang.Object
com.shaft.db.DatabaseActions
Direct Known Subclasses:
SHAFT.DB

public class DatabaseActions extends Object
  • Constructor Details

    • DatabaseActions

      public DatabaseActions(DatabaseActions.DatabaseType databaseType, String ip, String port, String name, String username, String password)
      This constructor is used for initializing the database variables that are needed to create new connections and perform queries
      Parameters:
      databaseType - database type that you want to connect with: DatabaseType.MY_SQL ,SQL_SERVER,POSTGRES_SQL.
      ip - IP address that has database installation that we need to connect to (e.g. 72.55.136.25)
      port - port of database installation on the server (e.g. 3306)
      name - database name that you need to connect to
      username - database username
      password - password of database user
    • DatabaseActions

      public DatabaseActions(String customConnectionString)
      This constructor is used for initializing the database variables that are needed to create new connections and perform queries
      Parameters:
      customConnectionString - custom database connection string ex: "jdbc:oracle:thin:@dbServerIP:dbPort:dbName"
  • Method Details

    • getInstance

      public static DatabaseActions getInstance(DatabaseActions.DatabaseType databaseType, String ip, String port, String name, String username, String password)
    • getInstance

      public static DatabaseActions getInstance(String customConnectionString)
    • getResult

      public static String getResult(ResultSet resultSet)
      Returns a string representation of the provided resultSet object
      Parameters:
      resultSet - the object returned as a result of performing a certain database query
      Returns:
      a string value which represents the provided resultSet object
    • getRow

      public static String getRow(ResultSet resultSet, String columnName, String knownCellValue)
      Returns a string value which represents the data of the target row
      Parameters:
      resultSet - the object returned as a result of performing a certain database query
      columnName - the name of the column holding the knownCellValue
      knownCellValue - a value that the engine searches for under the specified columnName, when that value is found, the row that contains it is read and added to the returned string
      Returns:
      a string value which represents the data of the target row
    • getColumn

      public static String getColumn(ResultSet resultSet, String columnName)
      Returns a string value which represents the data of the target column
      Parameters:
      resultSet - the object returned as a result of performing a certain database query
      columnName - the name of the target column that will be read
      Returns:
      a string value which represents the data of the target column
    • getRowCount

      public static int getRowCount(ResultSet resultSet)
      Returns the number of rows contained inside the provided resultSet
      Parameters:
      resultSet - the object returned as a result of performing a certain database query
      Returns:
      an integer value which represents the number of rows contained inside the provided resultSet
    • getResult

      public String getResult()
    • getRow

      public String getRow(String columnName, String knownCellValue)
    • getColumn

      public String getColumn(String columnName)
    • getRowCount

      public int getRowCount()
    • executeSelectQuery

      public ResultSet executeSelectQuery(String sql)
      Executes a SELECT statement and returns the result as a ResultSet object
      Parameters:
      sql - an SQL statement to be sent to the database, typically a static SQL SELECT statement
      Returns:
      a ResultSet object that contains the data produced by the given query; never null
    • executeUpdateQuery

      public int executeUpdateQuery(String sql)
      Executes any DML or DDL statement and returns the result as a ResultSet object
      Parameters:
      sql - an SQL Data Manipulation Language (DML) ;UPDATE statement, or an SQL statement that returns nothing, such as a DDL statement.
      Returns:
      either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
    • executeDDLStatement

      public void executeDDLStatement(String sql)
    • executeInsertQuery

      public int executeInsertQuery(String sql)
      Executes any DML or DDL statement and returns the result as a ResultSet object
      Parameters:
      sql - an SQL Data Manipulation Language (DML) ;INSERT statement, or an SQL statement that returns nothing, such as a DDL statement.
      Returns:
      either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
    • executeDeleteQuery

      public int executeDeleteQuery(String sql)
      Executes any DML or DDL statement and returns the result as a ResultSet object
      Parameters:
      sql - an SQL Data Manipulation Language (DML) ;DELETE statement, or an SQL statement that returns nothing, such as a DDL statement.
      Returns:
      either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing