0% found this document useful (0 votes)
15 views5 pages

Database Setup

The document provides instructions for setting up a MySQL database named 'bankdb' and creating a table for bank accounts. It includes a Java program, 'BankApp.java', that allows users to manage bank accounts by creating accounts, depositing, withdrawing money, and checking balances. The program connects to the database and uses JDBC for executing SQL commands based on user input.

Uploaded by

thrr2829
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

Database Setup

The document provides instructions for setting up a MySQL database named 'bankdb' and creating a table for bank accounts. It includes a Java program, 'BankApp.java', that allows users to manage bank accounts by creating accounts, depositing, withdrawing money, and checking balances. The program connects to the database and uses JDBC for executing SQL commands based on user input.

Uploaded by

thrr2829
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Database Setup (MySQL)

Before running the Java program, open your MySQL command line or MySQL Workbench and
execute:

CREATE DATABASE bankdb;

USE bankdb;

CREATE TABLE bank (

acc_no INT PRIMARY KEY,

name VARCHAR(50),

balance DOUBLE

);

---

⚙ Step 2: Java Code

Save this file as [Link]

import [Link].*;

import [Link].*;

public class BankApp {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

try {

// Step 1: Load JDBC Driver (optional for newer versions)

[Link]("[Link]");
// Step 2: Connect to Database

Connection con = [Link]("jdbc:mysql://localhost:3306/bankdb",


"root", ""); // change password if needed

[Link]("Connected to Database Successfully!\n");

while (true) {

[Link]("====== BANK MANAGEMENT SYSTEM ======");

[Link]("1. Create Account");

[Link]("2. Deposit Money");

[Link]("3. Withdraw Money");

[Link]("4. Check Balance");

[Link]("5. Exit");

[Link]("Enter your choice: ");

int ch = [Link]();

switch (ch) {

case 1:

[Link]("Enter Account No: ");

int acc = [Link]();

[Link]("Enter Name: ");

String name = [Link]();

[Link]("Enter Opening Balance: ");

double bal = [Link]();

String insert = "INSERT INTO bank VALUES(?, ?, ?)";

PreparedStatement ps1 = [Link](insert);

[Link](1, acc);

[Link](2, name);

[Link](3, bal);
[Link]();

[Link]("Account Created Successfully!\n");

break;

case 2:

[Link]("Enter Account No: ");

acc = [Link]();

[Link]("Enter Deposit Amount: ");

double dep = [Link]();

String deposit = "UPDATE bank SET balance = balance + ? WHERE acc_no = ?";

PreparedStatement ps2 = [Link](deposit);

[Link](1, dep);

[Link](2, acc);

int rows = [Link]();

if (rows > 0)

[Link]("Amount Deposited Successfully!\n");

else

[Link]("Account Not Found!\n");

break;

case 3:

[Link]("Enter Account No: ");

acc = [Link]();

[Link]("Enter Withdraw Amount: ");

double wd = [Link]();

String check = "SELECT balance FROM bank WHERE acc_no = ?";

PreparedStatement ps3 = [Link](check);

[Link](1, acc);

ResultSet rs = [Link]();
if ([Link]()) {

double current = [Link]("balance");

if (current >= wd) {

String withdraw = "UPDATE bank SET balance = balance - ? WHERE acc_no = ?";

PreparedStatement ps4 = [Link](withdraw);

[Link](1, wd);

[Link](2, acc);

[Link]();

[Link]("Amount Withdrawn Successfully!\n");

} else {

[Link]("Insufficient Balance!\n");

} else {

[Link]("Account Not Found!\n");

break;

case 4:

[Link]("Enter Account No: ");

acc = [Link]();

String view = "SELECT * FROM bank WHERE acc_no = ?";

PreparedStatement ps5 = [Link](view);

[Link](1, acc);

rs = [Link]();

if ([Link]()) {

[Link]("\nAccount No: " + [Link]("acc_no"));

[Link]("Name: " + [Link]("name"));

[Link]("Balance: ₹" + [Link]("balance") + "\n");

} else {
[Link]("Account Not Found!\n");

break;

case 5:

[Link]("Thank you for using the Banking System!");

[Link]();

[Link]();

[Link](0);

default:

[Link]("Invalid Choice!\n");

} catch (Exception e) {

[Link]("Error: " + e);

You might also like