mini project id
mini project id
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.*;
public class myjdbcproject {
2
System.out.println("7. Deposit Money to an Account");
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:
3
String name = br.readLine();
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:");
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;
n =stmt.executeUpdate(queryupdatePhone);
System.out.println(n+"Updated Successfully");
break;
case 3:
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");
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()) {
}
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
}
}
9
Test Cases: -
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
22