🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101

Bank account system with JDBC

A banking console app with accounts, deposits, withdrawals and transfers stored in MySQL, using transactions so money is never lost.

Intermediate⏱ 10–14 hours🊜 7 stepsJavaJDBCMySQL

What you'll learn

  • ◆JDBC connections and PreparedStatement
  • ◆Database transactions (commit/rollback)
  • ◆Hashing PINs

What you'll build

  • ✓Open account with a hashed 4-digit PIN
  • ✓Deposit, withdraw, check balance
  • ✓Transfer between accounts atomically
  • ✓Mini statement of last 10 transactions

Step-by-step guide

  1. 1

    Create tables

    accounts(acc_no PK, name, pin_hash, balance DECIMAL(12,2)) and transactions(id PK AUTO_INCREMENT, acc_no, type, amount, created_at).

  2. 2

    Connect

    Add the MySQL Connector/J dependency; DriverManager.getConnection(url, user, pass) using try-with-resources.

  3. 3

    Hash the PIN

    Never store the PIN itself. Use a salted hash (for example PBKDF2 via SecretKeyFactory "PBKDF2WithHmacSHA256").

  4. 4

    Deposit and withdraw

    UPDATE accounts SET balance = balance + ? WHERE acc_no = ?; for withdraw check balance >= amount in the same statement's WHERE.

  5. 5

    Transfer with a transaction

    conn.setAutoCommit(false); debit, credit, insert two transaction rows; commit(); on any exception rollback().

  6. 6

    Mini statement

    SELECT ... ORDER BY created_at DESC LIMIT 10.

  7. 7

    Layer the code

    AccountDao (SQL only), BankService (rules), Main (menu). This is how real backends are organised.

🚀 Make it stand out

  • +Add interest calculation each month
  • +Lock an account after 3 wrong PINs
  • +Turn it into a Spring Boot REST API