Bank Management System Java Project

Home » Coding » Basic Coding » Bank Management System Java Project

The Bank Management System Java Project creates a management system for banks to maintain users’ accounts & the fund’s data. We will use an SQL database to store information regarding Bank ID, name, and current balance. And finally, we’ll be using the Swing Library to develop a user-interactive GUI for our bank management system.

Introduction

To build this Java project, we will create a framework that takes input from the user for details like Bank ID, name, and amount. For the GUI, we’ll create 3 buttons that are, Deposit, Check Balance, and Withdraw, which function accordingly as per their name. Bank organizations can use this project to save and update their data in one place efficiently.

Objectives

The Bank Management System Java Project is designed to achieve the following objectives:

1. Bank Account Management: To create a simple system for managing a bank account. It allows for operations like depositing money, withdrawing money, and checking the account balance.

2. GUI Interaction: To use a Graphical User Interface (GUI) for interaction. Users can input their name, bank ID, and the amount they want to deposit or withdraw and can see their current balance.

3. Database Integration: To connect the system to MySQL database. This database stores account information, including the current balance. Whenever a user deposits or withdraws money, the balance in the database is updated accordingly.

4. Data Validation: To ensure that there are sufficient funds in the account before allowing a withdrawal. If the withdrawal amount exceeds the current balance, the user is informed that there are insufficient funds.

5. User Identification: Each user is identified by a unique name and bank ID. The system uses these to fetch and manipulate the correct account data from the database. This ensures that each user’s operations only affect their own account.

Requirements

1. Java Development Kit (JDK): As with any Java project, you need to have JDK installed on your system. It contains the runtime environment JRE and the compilers and debuggers necessary for development.

2. Integrated Development Environment (IDE): You would need an IDE like IntelliJ IDEA or Eclipse to write and manage your code effectively. These IDEs also come with built-in tools for code debugging, refactoring, version control, and other tasks.

3. Java Swing Library: We will use Java Swing for the GUI (Graphical User Interface). Swing comes pre-installed with JDK, so no extra installation is needed. However, knowledge of how to use Swing to create a user interface is crucial.

4. JDBC Driver: Since this project involves interacting with a database, you would need a JDBC (Java Database Connectivity) driver suitable for the type of database you’re using. In this case, the project is using MySQL, so you’ll need a MySQL JDBC driver.

5. MySQL Database: Our project is interacting with a MySQL database, so a MySQL server needs to be set up. You will also need to create the appropriate database and tables in the MySQL server and ensure that the application has the correct credentials (username, password) to connect to the database.

Source Code

package com.company;
public class Main {
public static void main(String[] args) {
new Bank();
}
}
package com.company;
import javax.swing.*;
import java.awt.*
import java.sql.*;
public class Bank {
private JTextField bankid;
private JTextField name;
private JButton DEPOSITButton;
private JButton WITHDRAWButton;
private JTextField amount;
private JLabel balance;
private JPanel bankPanel;
private JButton CHECKBALANCEButton;
private int currentBalance;
JFrame bankF = new JFrame();
public Bank() {
bankF.setContentPane(bankPanel);
bankF.pack();
bankF.setLocationRelativeTo(null);
bankF.setVisible(true);
DEPOSITButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
currentBalance=Integer.parseInt(balance.getText())+Integer.parseInt(amount.getText());
String sql = "UPDATE bank "+"SET CURRENT_BALANCE="+currentBalance+" WHERE NAME= '"+name.getText()+"'AND BANK_ID= '"+bankid.getText()+"'";
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern", "root", "root");
PreparedStatement myQuery= connection.prepareStatement(sql);
myQuery.executeUpdate();
JOptionPane.showMessageDialog(null,"AMOUNT DEPOSITED SUCCESSFULLY!");
}catch (Exception ex1){
System.out.println(ex1);
}
balance.setText(String.valueOf(currentBalance));
}
});
WITHDRAWButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(currentBalance<Integer.parseInt(amount.getText())){
JOptionPane.showMessageDialog(null,"INSUFFICIENT FUNDS IN YOUR ACCOUNT");
}else{
currentBalance=Integer.parseInt(balance.getText())-Integer.parseInt(amount.getText());
String sql = "UPDATE bank "+"SET CURRENT_BALANCE="+currentBalance+" WHERE NAME= '"+name.getText()+"'AND BANK_ID= '"+bankid.getText()+"'";
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern", "root", "root");
PreparedStatement myQuery = connection.prepareStatement(sql);
myQuery.executeUpdate();
JOptionPane.showMessageDialog(null,"AMOUNT WITHDRAWN SUCCESSFULLY!");
}catch (Exception ex1){
System.out.println(ex1);
}
balance.setText(String.valueOf(currentBalance));
}
}
});
CHECKBALANCEButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String sql1 = "SELECT CURRENT_BALANCE from bank WHERE NAME= '"+name.getText()+"' AND BANK_ID= '"+bankid.getText()+"'";
if(name.getText().equals("")||bankid.getText().equals("")){
JOptionPane.showMessageDialog(null,"Enter Name and Bank Id to check");
}
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern", "root", "root");
Statement myQuery = connection.createStatement();
ResultSet rs = myQuery.executeQuery(sql1);
while(rs.next()){
currentBalance = rs.getInt(1);
}
balance.setText(String.valueOf(currentBalance));
}catch (Exception ex){
JOptionPane.showMessageDialog(null,"NOT FOUND");
}
}
});
}
}

Explanation of the Code

The Online Bank Management System Java Project code can be broken down into two sections. One involves creating the GUI, and the other is the retrieval of information from the SQL database of the user. Let’s see the GUI first:

1. It consists of 3 textfields’ that require the bank details of users to access their accounts.

2. It has 3 buttons for depositing, checking & withdrawing funds in a bank account.

3. It has a Jlable that reflects the current bank balance.

Now let’s have a look at the functions:

1. main function: This function serves as the entry point of the application. It creates a new instance of the Bank class, which sets up the GUI for the banking application.

2. Bank() Constructor: The constructor of the Bank class sets up the GUI window for the bank application, specifies action listeners for the “DEPOSIT”, “WITHDRAW”, and “CHECK BALANCE” buttons, and handles related actions.

3. DEPOSIT Button Action Listener: This code runs when the “DEPOSIT” button is clicked. It updates the current balance by adding the amount entered by the user to the existing balance. It then updates this balance in the database. If an error occurs during this process, it is caught and printed.

4. WITHDRAW Button Action Listener: This code runs when the “WITHDRAW” button is clicked. It first checks if the current balance is sufficient for the withdrawal. If the balance is sufficient, it deducts the entered amount from the current balance and updates the balance in the database. If the balance is insufficient, it shows an “INSUFFICIENT FUNDS IN YOUR ACCOUNT” message. Any errors that occur during this process are caught and printed.

5. CHECK BALANCE Button Action Listener: This code runs when the “CHECK BALANCE” button is clicked. It checks the current balance from the database for the user with the entered name and bank ID. If the fields are empty, it shows an “Enter Name and Bank Id to check” message. If an error occurs during this process, it shows a “NOT FOUND” message.

Output

Main Interface

Conclusion

In conclusion, the Bank Management System is a user-friendly Java project that combines GUI and database interactions to create a functional banking application. It ably simulates common banking processes such as depositing money, withdrawing funds, and checking account balances in a secure and efficient manner.

This Java project illustrates how software can be used to manage and automate financial transactions, improving convenience for both the institution and the customer. Furthermore, by ensuring users can only perform transactions on their own accounts and validating transactions for sufficient funds, it maintains a high level of data integrity and security.

Therefore, this Bank Management System Java project is a great demonstration of the power of programming in real-world applications. It provides a robust basis for more comprehensive banking software, which could include additional features such as fund transfers, different account types, loan management, and more.

More Java Projects>>>

You May Also Like To Create…