Skip to main content

Exploring the Account Class

Account Class Overview

The Account class represents a bank account and extends the HBankDataAccess class, which provides database access functionality. It includes various fields such as customerNumber, sortcode, accountNumber, type, interestRate, opened, overdraftLimit, lastStatement, nextStatement, availableBalance, and actualBalance to store account-related information.

Constants and SQL Queries

The class defines several constants for SQL queries and account attributes, such as GET_ACCOUNT, GET_ACCOUNTS, ACCOUNT_NUMBER, and ACCOUNT_TYPE. These constants are used in the methods to perform database operations related to accounts.

Methods for Account Operations

The Account class provides multiple methods to perform operations on accounts, including creating, updating, deleting, and retrieving account information. For example, the createAccount method is used to create a new account, the updateAccount method updates existing account information, and the getAccount method retrieves account details.

Example: Updating Account Information

The updateThis method updates the account details in the database. This method opens a connection to the database, prepares an SQL update statement, and executes it to update the account information based on the current state of the Account object.


The updateThis method in the Account class demonstrates how to update account details in the database. It prepares an SQL update statement and executes it to update the account information based on the current state of the Account object.

	public void updateThis()
{
openConnection();

String sql = "UPDATE ACCOUNT SET ACCOUNT_TYPE = ? ,ACCOUNT_INTEREST_RATE = ? ,ACCOUNT_OVERDRAFT_LIMIT = ? ,ACCOUNT_LAST_STATEMENT = ? ,ACCOUNT_NEXT_STATEMENT = ? ,ACCOUNT_AVAILABLE_BALANCE = ? ,ACCOUNT_ACTUAL_BALANCE = ? WHERE ACCOUNT_NUMBER like ? AND ACCOUNT_SORTCODE like ?";
try (PreparedStatement stmt = conn.prepareStatement(sql);)
{
stmt.setString(1, this.type);
stmt.setDouble(2, this.interestRate);
stmt.setInt(3, this.overdraftLimit);
stmt.setString(4, this.lastStatement.toString());
stmt.setString(5, this.nextStatement.toString());
stmt.setDouble(6, this.availableBalance);
stmt.setDouble(7, this.actualBalance);
stmt.setString(8, this.accountNumber);
stmt.setString(9, this.sortcode);
stmt.executeUpdate();
}
catch (SQLException e)
{
logger.severe(e.toString());

 

This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human