Mini Banking Application in Java
In any Bank Transaction, there are several parties involved to process transaction like a merchant, bank, receiver, etc. so there are several numbers reasons that transaction may get failed, declined, so to handle a transaction in Java, there is a JDBC (Java Database Connectivity) which provides us an API to connect, execute, fetch data from any databases. It provides the language Java database connectivity standards. It is used to write programs required to access databases.
Transactions in JDBC provide us a feature that considers a complete SQL statement as one unit, then executes once, and if any statement fails, the entire transaction fails. To use transaction, we have to set setAutoCommit(false); manually, and once all the statements are executed successfully, making changes in the database’s commit() method will be required.
In this Mini Banking Application, to handle a transaction, we are using JDBC Transaction to make transactions consistent. This Application Provides Menu-Driven Console Interface to a User Using that User can perform functions like create Account, Login, View Balance And Transfer Money To The Other Customer.
MySQL is a full-featured relational database management system (RDBMS). MySQL is a free, open-source relational database management system that uses Structured Query Language (SQL), the most popular language for adding, accessing, and processing data in a database. MySQL is noted for its speed, reliability, and flexibility.
Eclipse is an IDE (interactive development environment) written to develop and debug (primarily) Java code. It contains a base workspace and an extensible plug-in system for customizing the environment.
Step 1: Create Database name bank
Step 2: Create Table name customer
// Create a database CREATE DATABASE BANK; // Create table CREATE TABLE `customer` ( `ac_no` int NOT NULL AUTO_INCREMENT, `cname` varchar(45) DEFAULT NULL, `balance` varchar(45) DEFAULT NULL, `pass_code` int DEFAULT NULL, PRIMARY KEY (`ac_no`), UNIQUE KEY `cname_UNIQUE` (`cname`) ) ;
Eclipse Project Setup:
- Create New Project
- Create A package name banking
Create a Connection class in the banking package
Step 1: Include JDBC Driver for MySQL
// register jdbc Driver String mysqlJDBCDriver = "com.mysql.cj.jdbc.Driver"; Class.forName(mysqlJDBCDriver);
Step 2: Create Connection Class using MySQL username and password
// Create Connection String url = "jdbc:mysql://localhost:3306/mydata"; String user = "root"; String pass = "123"; con = DriverManager.getConnection(url, user, pass);
Purpose: This class returns a Global Databases Connection using the object of connection all the commands will be executed.
Note: Create a Bank Management Class in the banking package
Purpose: This class will provide all the methods of Bank Management like transferring money, viewing balance, creating an account, and log in.
Note: Create a User Menu Class (bank.java) in the banking package.
Output: This class provides a Menu-Driven Interface to the Customer where the Customer can create Account, Login Account, Transfer Money, etc.
->|| Welcome to InBank ||<- 1)Create Account 2)Login Account Enter Input:2 Enter UserName:pritesh Enter Password:123
Enter UserName:pritesh Enter Password:123 Hallo, pritesh 1)Transfer Money 2)View Balance 5)LogOut Enter Choice:2 ----------------------------------------------------------- Account No Name Balance 112 pritesh 0.00 -----------------------------------------------------------
Hallo, pritesh 1)Transfer Money 2)View Balance 5)LogOut Enter Choice:1 Enter Receiver A/c No:110 Enter Amount:5000 Insufficient Balance! ERR : Failed!
Hallo, pritesh 1)Transfer Money 2)View Balance 5)LogOut Enter Choice:5 MSG : Logout Successfully!