Before reading further, read the previous part of this article.
Now we are here to explain the procedure involved in the transactions of an authorized customer with a suitable example of it.
Transactions involved for Authorized Customers
To explain this module, we will make two separate Java files, CustomerMain.java and ConnectDB.java.
CustomerMain.java consists of all the functionality required for the customer and ConnectDB.java will be used to connect the file with the MySQL database in which all the details are written about the customer.
Here are the few processes that can be done for the customer:
- Can check his/her details (a detail consists of account number, password, name, address, contact, account balance)
- Can change his/her password
- Can withdraw his/her money
Now let's check how all these processes can be done with the following code example.
Example
ConnectDB.java
- package mydb;
- import java.sql.*;
-
- public class ConnectDB {
- public Connection c() throws Exception{
- Class.forName ("com.mysql.jdbc.Driver");
- Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/bankdb", "root", "toor");
- return con;
- }}
In the preceding code, we can observe that the ConnectDB.java file is made in the separate package named “mydb”. The ("jdbc:mysql://localhost:3306/bankdb", "root", "toor") is the path for the database. The “bankdb” is the name of the table made in the database, “root” is the username and “toor” is the password of the MySQL access and “3306” is the port number.
For the connection, there is also one jar file that is necessary named “MySQL-Connector” that should be attached to the library of your project. The jar file is also attached with the codes file.
Here are the following tables for a customer, employee, and administrator.
For now, we are working with the customer schema table and the following are the contents of the customer table.
Now the main Java file is the following.
CustomerMain.java
We get the outputs for the customer named himanshu.
The following are the outputs associated with the various transactions.
Output 1: display my details
Output 2: Change my password
Output 3: Withdraw money
Output 4: If any of the input parameters are incorrect.
Output 5: If you choose other than the given option.
For the discussion on the employee module, click the below link
Accessing Database Using Java and MySQL: Part 3
Thank you, keep learning and sharing.