The preceding article begins with the explanation of the administrator module for various transactions.
Before reading further, read the previous part of this article.
- Accessing Database Using Java and MySQL: Part 1
- Accessing Database Using Java and MySQL: Part 2
- Accessing Database Using Java and MySQL: Part 3
Transactions involved for Authorized Administrator

This module is also made by the two separate Java files AdminMain.java and ConnectDB.java.
The following are transactions associated with the administrator:
- Can check details of any customer.
- Can check details of any employee.
- Can change the password of any customer.
- Can change the password of any employee.
- Can change his/her password.
The database schema table created for the admin is the following:
For now, we are working with admin schema table, so the following are the contents of the admin table.


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;
- }
- }
- import java.sql.*;
- import java.io.*;
- import mydb.ConnectDB;
- class Admin{
- BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
- void Dtl_of_Customer(String accnt)
- {
- try{
- ConnectDB ob = new ConnectDB();
- Connection con = ob.c();
- Statement stm = con.createStatement();
- ResultSet rst = stm.executeQuery("select * from customer where accno='"+accnt+"'");
- Customer obj1=new Customer();
- obj1.display_Customer(accnt);
- }
- catch(Exception e)
- {
- System.out.println("Admin see customer details method"+e);
- }
- }
- void Dtl_of_emp(String id)
- {
- try
- {
- ConnectDB ob = new ConnectDB();
- Connection con = ob.c();
- Statement stm = con.createStatement();
- ResultSet rst = stm.executeQuery("select * from employee where EmpID='"+id+"'");
- Employee obj2=new Employee();
- obj2.Employee_dtl(id);
- }
- catch(Exception e)
- {
- System.out.println("Admin see employee detail method"+e);
- }
- }
- void Password_change_cust(String acc)
- {
- try
- {
- ConnectDB ob = new ConnectDB();
- Connection con = ob.c();
- Statement stm = con.createStatement();
- System.out.print("Enter customer's new password: ");
- String p1=in.readLine();
- System.out.print("Confirm password: ");
- String p2=in.readLine();
- if(p1.equals(p2))
- {
- stm.executeUpdate("update customer set password='"+p1+"' where accno='"+acc+"'");
- System.out.println("password updated successfully...");
- }
- else
- {
- System.out.println("password does not match");
- }
- }
- catch(Exception e)
- {
- System.out.println("Change cust pass method"+e);
- }
- }
- void Password_change_emp(String id)
- {
- try
- {
- ConnectDB ob = new ConnectDB();
- Connection con = ob.c();
- Statement stm = con.createStatement();
- System.out.print("Enter employee's new password: ");
- String p1=in.readLine();
- System.out.print("Confirm password: ");
- String p2=in.readLine();
- if(p1.equals(p2))
- {
- stm.executeUpdate("update employee set password='"+p1+"' where EmpID='"+id+"'");
- System.out.println("password updated successfully...");
- }
- else
- {
- System.out.println("password does not match");
- }
- }
- catch(Exception e)
- {
- System.out.println("Change cust emp method"+e);
- }
- }
- void Change_my_pass(String y,String p)
- {
- try
- {
- ConnectDB ob = new ConnectDB();
- Connection con = ob.c();
- Statement stm = con.createStatement();
- System.out.print("Enter new password: ");
- String p1=in.readLine();
- System.out.print("Confirm password: ");
- String p2=in.readLine();
- if(p1.equals(p2))
- {
- stm.executeUpdate("update employee set password='"+p1+"' where EmpID='"+y+"' and password='"+p+"'");
- System.out.println("password updated successfully...");
- }
- else
- {
- System.out.println("password does not match");
- }
- }
- catch(Exception e){
- System.out.println("Change my pass method"+e);
- }
- }
- }
- public class AdminMain {
- public static void main(String[] args) throws Exception{
- try
- {
- BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
- System.out.println("Administrator..??");
- System.out.println("1-Yes or 2-No");
- int choice0=Integer.parseInt(in.readLine());
- String acc;
- switch(choice0)
- {
- case 1:
- System.out.print("Enter the Username of Admin: ");
- String y = in.readLine();
- System.out.print("Enter the password: ");
- String p = in.readLine();
- ConnectDB obm = new ConnectDB();
- Connection con = obm.c();
- Statement stm = con.createStatement();
- ResultSet rst = stm.executeQuery("select * from admin where username='"+y+"' and password = '"+p+"'");
- Admin oba = new Admin();
- if(rst.next())
- {
- System.out.println("1-Display details of any customer");
- System.out.println("2-Display details of any employee");
- System.out.println("3-Change password of any customer");
- System.out.println("4-Change password of any employee");
- System.out.println("5-Change my password");
- System.out.print ("enter your choice: ");
- int choice11=Integer.parseInt(in.readLine());
- switch(choice11)
- {
- case 1:System.out.print("Enter A/C of any customer: ");
- String acct =in.readLine();
- oba.Dtl_of_Customer(acct);
- break;
- case 2:System.out.print("Enter Id of any employee: ");
- String id =in.readLine();
- oba.Dtl_of_emp(id);
- break;
- case 3:System.out.print("Enter any customer's A/C #: " );
- String accn=in.readLine();
- oba.Password_change_cust(accn);
- break;
- case 4:System.out.print("Enter any employee's Id: ");
- String empid=in.readLine();
- oba.Password_change_emp(empid);
- break;
- case 5:oba.Change_my_pass(y, p);
- break;
- default:System.out.println("Wrong choice");
- }
- }
- else
- {
- System.out.println("Invalid A/C or password");
- }
- break;
- default:System.out.println("Thank you");
- }
- }
- catch(Exception e)
- {
- System.out.println("main method:"+e);
- }
- }
- }
Various outputs
Output 1: Can check details of any customer.

Here are the outputs of checking the details of two customers by the two admins “eddys” and “ashish” for “gaurav” and “rahul”.


Again here are the outputs of checking the details of the two employees by two admins “avadh” and “ashish” for “Gops” and “Abhi”.

Output 3: Can change the password of any customer.

The Customer password is now changed.

Output 4: Can change the password of any employee.


The Employee password is now changed.

Output 5: Can change his/her password.

Likewise, you can also add other authorization for an admin or customer or an employee.
The next part explains the entire module together in which a person gets the option to choose his status using the authentication process and it will be some other aspect.
Thank you, keep learning and sharing.

Atul GuptaPosted Jun 4, 2015, 7:52 AM
Informative, thanks for sharing .
Gopi ChandPosted Jun 4, 2015, 2:01 AM
Very happy to see the appreciation from you all...thanks :)
Neeraj KumarPosted Jun 3, 2015, 10:06 PM
nice
Abhishek JaiswalPosted Jun 3, 2015, 4:13 PM
Keep it up #javaGuy!! :)
Santhakumar MunuswamyPosted Jun 3, 2015, 2:44 PM
Thanks for nice one
NitinPosted Jun 3, 2015, 9:20 AM
good one