-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBalanceEnquiry.java
More file actions
39 lines (32 loc) · 1.16 KB
/
Copy pathBalanceEnquiry.java
File metadata and controls
39 lines (32 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import javax.swing.*;
import java.awt.*;
import java.sql.*;
public class BalanceEnquiry extends JFrame {
BalanceEnquiry(String cardNumber) {
setTitle("Balance Enquiry");
setLayout(new BorderLayout());
JLabel label = new JLabel("", JLabel.CENTER);
label.setFont(new Font("Arial", Font.BOLD, 18));
add(label, BorderLayout.CENTER);
try {
Conn conn = new Conn();
ResultSet rs = conn.s.executeQuery("SELECT * FROM bank WHERE card_number = '" + cardNumber + "'");
int balance = 0;
while (rs.next()) {
String type = rs.getString("type");
int amount = Integer.parseInt(rs.getString("amount"));
balance += type.equals("Deposit") ? amount : -amount;
}
label.setText("Current Balance: Rs. " + balance);
} catch (Exception e) {
label.setText("Error fetching balance.");
e.printStackTrace();
}
setSize(400, 200);
setLocation(500, 300);
setVisible(true);
}
public static void main(String[] args) {
new BalanceEnquiry("1234567890123456");
}
}