0% found this document useful (0 votes)
1 views

mini project id

Uploaded by

AVIJEET Swain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

mini project id

Uploaded by

AVIJEET Swain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Assignment 6: Mini project using JDBC connectivity

Objective of this Assignment:


To design a miniature Project for a Banking Management System using Java, Oracle and
JDBC.

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.sql.*;
public class myjdbcproject {

public static void main(String[] args) throws IOException {


// TODO Auto-generated method stub Connection
con=null;
Statement stmt=null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String conurl="jdbc:oracle:thin:@localhost:1521:XE";
con=DriverManager.getConnection(conurl,"system","admin");
System.out.println("Connection is established");
stmt=con.createStatement();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int ch = 0;
do {
System.out.println("\n\n***** Banking Management System*****");

// Display the menu


System.out.println("1. Show Customer Records");

System.out.println("2. Add Customer Record");

System.out.println("3. Delete Customer Record");

System.out.println("4. Update Customer Record for any


attribute except Customer Number");
System.out.println("5. Show Account Details of a Customer");

System.out.println("6. Show Loan Details of a Customer");

2
System.out.println("7. Deposit Money to an Account");

System.out.println("8. Withdraw Money from an Account");


System.out.println("9. Exit the Program");

System.out.println("Enter your choice(1-9):");


// Accept user's choice
ch=Integer.parseInt(br.readLine());
switch(ch) {
case 1:
// Display customer records
String sqlstr = "select * from CUSTOMER";

ResultSet rs = stmt.executeQuery(sqlstr);
int a = 0; while(rs.next()) {

System.out.print('\n'+rs.getString("CUST_NO")+'\t');
System.out.print('\t'+rs.getString("NAME"));

System.out.print('\t'+rs.getString("PHONE_NO"));
System.out.print('\t'+rs.getString("CITY")); a++;
}
System.out.println();
System.out.println("The number of rows selected is "+ a);

break;
case 2:

// Add customer record


// Accept input for each column from user
System.out.println("Enter cust_no: \t"); String cust_no =
br.readLine(); System.out.println("Enter the name: \t");

3
String name = br.readLine();

System.out.println("Enter the phone: \t");

long phone = Long.parseLong(br.readLine());


System.out.println("Enter the city: \t");

String city = br.readLine();


String insertstmt = "insert into customer
values('"+cust_no+"','"+name+"','"+phone+"','"+city+"')";
int n =stmt.executeUpdate(insertstmt);
System.out.println(n+"Row Inserted");
break;
case 3:
System.out.println("Enter a cust_no for deletion: \t");
String cust = br.readLine();
String deletestmt = "delete from customer where
cust_no='"+cust+"'";

n = stmt.executeUpdate(deletestmt);
System.out.println(n+"Row deleted");
break;

case 4:
// Update customer record
// Accept customer number from user
System.out.println("Enter 1: For Name 2: For Phone no 3: For City to update:");

// Accept user's choice


int c1=Integer.parseInt(br.readLine());

switch(c1)
{
case 1:
// Update name of the customer
System.out.println("Enter Cust No");

4
cust_no =br.readLine(); System.out.println("Enter updated
name"); String updatedName =br.readLine();
String queryupdateName = "Update Customer set Name = '"
+ updatedName + "' where Cust_no = '"+cust_no+"'";

n =stmt.executeUpdate(queryupdateName);
System.out.println(n+"Updated Successfully"); break;

case 2: // Update customer's phone number


System.out.println("Enter Cust No");
cust_no =br.readLine();
System.out.println("Enter updated Phone");
long updatedPhone

=Long.parseLong(br.readLine()); String queryupdatePhone = "Update Customer


set Name = '" + updatedPhone + "' where Cust_no = '"+cust_no+"'";

n =stmt.executeUpdate(queryupdatePhone);
System.out.println(n+"Updated Successfully");

break;
case 3:

// Update customer's city


System.out.println("Enter Cust No");
cust_no =br.readLine();
System.out.println("Enter updated City");
String updatedCity =br.readLine();
String queryupdateCity = "Update Customer set
Name = '" + updatedCity + "' where Cust_no = '"+cust_no+"'";

5
n =stmt.executeUpdate(queryupdateCity);
System.out.println(n+"Updated Successfully");

break;
}
break;
case 5:
System.out.println("Enter Cust No"); cust_no =
br.readLine();
String queryAccDeatils= "SELECT A.ACCOUNT_NO, A.TYPE,
A.BALANCE, B.BRANCH_CODE,B.BRANCH_NAME,B.BRANCH_CITY FROM ACCOUNT A, BRANCH B,
CUSTOMER C, DEPOSITOR D WHERE D.ACCOUNT_NO = A.ACCOUNT_NO AND A.BRANCH_CODE =
B.BRANCH_CODE AND C.CUST_NO = D.CUST_NO AND C.CUST_NO = '"+cust_no+"'";
rs = stmt.executeQuery(queryAccDeatils);
System.out.format("Acc. No.: \tType: \tBalance:
\tBranch Code: \tBranch Name: \t\tBranch City:\n");
while(rs.next()) {
String account_no = rs.getString("ACCOUNT_NO");

String type = rs.getString("TYPE");


Long balance = rs.getLong("BALANCE"); String
branch_code =
rs.getString("BRANCH_CODE");
String branch_name =
rs.getString("BRANCH_NAME");
String branch_city = rs.getString("BRANCH_CITY");

System.out.format("%s \t\t%s \t %d\t\t %s\t\t %s\t


%s\t\n", account_no, type, balance, branch_code, branch_name, branch_city);
}
break;
case 6:

6
System.out.println("Enter Cust No"); cust_no =
br.readLine();
String queryLoanNumber= "SELECT C.*, L.LOAN_NO,
L.AMOUNT, B.* FROM LOAN L, CUSTOMER C, BRANCH B WHERE L.BRANCH_CODE =
B.BRANCH_CODE AND C.CUST_NO = L.CUST_NO AND
C.CUST_NO = '"+cust_no+"'";
rs = stmt.executeQuery(queryLoanNumber); System.out.println(rs+"
no of rows affected"); while(rs.next()) {

String ccust = rs.getString("CUST_NO"); String cname


= rs.getString("NAME"); Long cphone =
rs.getLong("PHONE_NO"); String ccity =
rs.getString("CITY");

String loan_no = rs.getString("LOAN_NO"); Long amount =


rs.getLong("AMOUNT"); String branch_code =

rs.getString("BRANCH_CODE"); String branch_name =


rs.getString("BRANCH_NAME");
String branch_city = rs.getString("BRANCH_CITY");
// System.out.format("Loan. No.: \tCust. No.: \tAmount:
\tBranch Code\n");
System.out.format("%s %s %d %s %s %d %s %s %s
\n",ccust, cname, cphone, ccity, loan_no, amount, branch_code, branch_name,branch_city);

}
break;
case 7:

7
//Deposit money
// Accept the account number to be deposited in
// Message for transaction completion
System.out.println("Enter Account No"); String acc_no =
br.readLine();
System.out.println("Enter the amount to deposite"); long amt =
Long.parseLong(br.readLine());
String queryAddMoney = "Update ACCOUNT set BALANCE =
BALANCE +" + amt + "where ACCOUNT_NO = '"+acc_no+"'";
n =stmt.executeUpdate(queryAddMoney);
System.out.println(n+"Balance Updated"); break;
case 8:
//Withdraw money
// Accept the account number to be withdrawn from
// Handle appropriate withdral ckeck conditions
// Message for transaction completion
System.out.println("Enter Account No"); acc_no =
br.readLine();
System.out.println("Enter the amount to deposite"); amt =
Long.parseLong(br.readLine());
String queryCheckBalance = "Select BALANCE from
ACCOUNT where ACCOUNT_No = '" + acc_no +"'";
rs = stmt.executeQuery(queryCheckBalance);
while(rs.next()) {
long bal = rs.getInt(1); if(amt <=
bal) {
String querySubMoney = "Update ACCOUNT set
BALANCE = BALANCE -" + amt + "where ACCOUNT_NO =
'"+acc_no+"'";
n =stmt.executeUpdate(querySubMoney);

8
System.out.println(n+" Balance
Updated");
}
else {
System.out.println("Insuffient balance");

}
}
break;
case 9:
// Exit the menu System.out.println("Visit us next
time"); stmt.close();
con.close();
System.exit(0);
break;
default:
// Handle wrong choice of option System.out.println("Enter from 1 to 9
nothing else

please again "); break;


}
}while(ch!=9);
}
catch(Exception e){
System.out.println(e);
}

}
}

9
Test Cases: -

1. Show Customer Records

10
2. Add Customer Record: <C0011, ANWESHA DAS, 9999999999, BHUB>, < c0012, SACHIN SINGH, 9898989898,
CTC>, <C0013, ARJUN MISHRA, 7777777777, BBSR>

11
3

12
3. Delete Customer Record: <C0013>, <C0016>

13
4. Update Customer Record for any attribute except Customer Number: <C0011>

14
5. Show Account Details of a Customer: <C0003>, <c0005>, <C

15
16
6. Show Loan Details of a Customer: <C0003>, <c0005>, <C0008>, <C0016>

17
18
7. Deposit Money to an Account: <A0008, 800>, <a0005, 10000>

19
8. Withdraw Money from an Account: <A0008, 800>, <A0008, 8000><a0005, 10000>

20
21
9. Exit the Program

10. Enter choice 10Enter choice 10

22

You might also like