# Banking System Account management, transactions, aur fund transfer ka system. ## Features - Account create karna (Savings / Current) - Deposit aur Withdrawal - Fund Transfer between accounts - Transaction history dekhna - Balance check karna - Interest calculate karna ## Technology Stack - Java SE 17+ - JDBC - MySQL - Transaction Management ## Database Setup ```sql CREATE DATABASE banking_db; USE banking_db; CREATE TABLE accounts ( id INT PRIMARY KEY AUTO_INCREMENT, account_number VARCHAR(20) UNIQUE NOT NULL, holder_name VARCHAR(100) NOT NULL, account_type ENUM('SAVINGS','CURRENT') DEFAULT 'SAVINGS', balance DOUBLE DEFAULT 0, is_active BOOLEAN DEFAULT TRUE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE transactions ( id INT PRIMARY KEY AUTO_INCREMENT, account_number VARCHAR(20), type ENUM('DEPOSIT','WITHDRAWAL','TRANSFER_IN','TRANSFER_OUT'), amount DOUBLE, balance_after DOUBLE, description VARCHAR(200), transaction_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (account_number) REFERENCES accounts(account_number) ); ``` ## Account Model ```java package model; public class Account { private int id; private String accountNumber; private String holderName; private String accountType; private double balance; private boolean isActive; public Account() {} public Account(String holderName, String accountType, double initialBalance) { this.holderName = holderName; this.accountType = accountType; this.balance = initialBalance; this.accountNumber = generateAccountNumber(); this.isActive = true; } private String generateAccountNumber() { return "ACC" + System.currentTimeMillis() % 10000000; } // Getters aur Setters public int getId() { return id; } public void setId(int id) { this.id = id; } public String getAccountNumber() { return accountNumber; } public void setAccountNumber(String accountNumber) { this.accountNumber = accountNumber; } public String getHolderName() { return holderName; } public void setHolderName(String holderName) { this.holderName = holderName; } public String getAccountType() { return accountType; } public void setAccountType(String accountType) { this.accountType = accountType; } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public boolean isActive() { return isActive; } public void setActive(boolean active) { isActive = active; } @Override public String toString() { return String.format("Account: %s | Holder: %s | Type: %s | Balance: Rs.%.2f | Status: %s", accountNumber, holderName, accountType, balance, isActive ? "Active" : "Inactive"); } } ``` ## BankingService — Core Logic ```java package service; import dao.*; import model.*; import util.DBConnection; import java.sql.Connection; public class BankingService { private AccountDAO accountDAO = new AccountDAO(); private TransactionDAO transactionDAO = new TransactionDAO(); public Account createAccount(String name, String type, double initialDeposit) throws Exception { if (initialDeposit < 500) throw new Exception("Minimum initial deposit Rs.500"); Account acc = new Account(name, type, initialDeposit); accountDAO.insert(acc); transactionDAO.insert(acc.getAccountNumber(), "DEPOSIT", initialDeposit, initialDeposit, "Account opening deposit"); return acc; } public double deposit(String accNum, double amount) throws Exception { if (amount <= 0) throw new Exception("Invalid deposit amount"); Account acc = accountDAO.findByNumber(accNum) .orElseThrow(() -> new Exception("Account not found")); if (!acc.isActive()) throw new Exception("Account is inactive"); double newBalance = acc.getBalance() + amount; accountDAO.updateBalance(accNum, newBalance); transactionDAO.insert(accNum, "DEPOSIT", amount, newBalance, "Cash deposit"); return newBalance; } public double withdraw(String accNum, double amount) throws Exception { if (amount <= 0) throw new Exception("Invalid amount"); Account acc = accountDAO.findByNumber(accNum) .orElseThrow(() -> new Exception("Account not found")); if (!acc.isActive()) throw new Exception("Account is inactive"); if (acc.getBalance() < amount) throw new Exception("Insufficient balance"); double minBalance = acc.getAccountType().equals("SAVINGS") ? 500 : 1000; if (acc.getBalance() - amount < minBalance) throw new Exception("Minimum balance Rs." + minBalance + " maintain karna jaruri hai"); double newBalance = acc.getBalance() - amount; accountDAO.updateBalance(accNum, newBalance); transactionDAO.insert(accNum, "WITHDRAWAL", amount, newBalance, "Cash withdrawal"); return newBalance; } public void transfer(String fromAcc, String toAcc, double amount) throws Exception { if (amount <= 0) throw new Exception("Invalid amount"); try (Connection conn = DBConnection.getConnection()) { conn.setAutoCommit(false); try { Account from = accountDAO.findByNumber(fromAcc) .orElseThrow(() -> new Exception("Source account not found")); Account to = accountDAO.findByNumber(toAcc) .orElseThrow(() -> new Exception("Destination account not found")); if (from.getBalance() < amount) throw new Exception("Insufficient balance"); double newFromBalance = from.getBalance() - amount; double newToBalance = to.getBalance() + amount; accountDAO.updateBalance(fromAcc, newFromBalance); accountDAO.updateBalance(toAcc, newToBalance); transactionDAO.insert(fromAcc, "TRANSFER_OUT", amount, newFromBalance, "Transfer to " + toAcc); transactionDAO.insert(toAcc, "TRANSFER_IN", amount, newToBalance, "Transfer from " + fromAcc); conn.commit(); System.out.println("Transfer successful! Rs." + amount + " transferred."); } catch (Exception e) { conn.rollback(); throw e; } } } } ```