-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfile.java
More file actions
132 lines (106 loc) · 4.2 KB
/
Copy pathProfile.java
File metadata and controls
132 lines (106 loc) · 4.2 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import javax.swing.*;
import java.awt.*;
import java.sql.*;
class Profile extends JFrame {
String result = "";
Profile(String username) {
Font f = new Font("Futura", Font.BOLD, 35);
Font f2 = new Font("Calibri", Font.PLAIN, 20);
JLabel title = new JLabel("Profile Settings", JLabel.CENTER);
title.setFont(f);
JLabel l1 = new JLabel("Select Field to Update:");
JComboBox<String> box = new JComboBox<>(new String[]{"Username", "Password", "Phone", "Email"});
JLabel l2 = new JLabel("Enter New Value:");
JTextField t1 = new JTextField(15);
JButton b1 = new JButton("Update");
JButton b2 = new JButton("Back");
l1.setFont(f2);
box.setFont(f2);
l2.setFont(f2);
t1.setFont(f2);
b1.setFont(f2);
b2.setFont(f2);
Container c = getContentPane();
c.setLayout(null);
title.setBounds(250, 20, 300, 40);
l1.setBounds(200, 100, 200, 30);
box.setBounds(400, 100, 200, 30);
l2.setBounds(200, 160, 200, 30);
t1.setBounds(400, 160, 200, 30);
b1.setBounds(250, 220, 120, 40);
b2.setBounds(400, 220, 120, 40);
c.add(title);
c.add(l1);
c.add(box);
c.add(l2);
c.add(t1);
c.add(b1);
c.add(b2);
b1.addActionListener(
a->
{
String s1 = box.getSelectedItem().toString().toLowerCase();
String s2 = t1.getText();
if (s2.isEmpty())
{
JOptionPane.showMessageDialog(null,"Inappropriate Credentials");
return;
}
String url = "jdbc:mysql://localhost:3306/3dec";
try(Connection con = DriverManager.getConnection(url,"root","Mehta@17"))
{
String sql = "update users set "+s1+"=? where username=?";
try(PreparedStatement pst = con.prepareStatement(sql))
{
pst.setString(1,s2);
pst.setString(2,username);
pst.executeUpdate();
JOptionPane.showMessageDialog(null,"Profile successfully updated");
t1.setText("");
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
return;
}
if (s1.equals("username"))
{
new Profile(s2);
dispose();
try(Connection con = DriverManager.getConnection(url,"root","Mehta@17"))
{
String sql = "update transactions set "+s1+"=? where username=?";
try(PreparedStatement pst = con.prepareStatement(sql))
{
pst.setString(1,s2);
pst.setString(2,username);
pst.executeUpdate();
JOptionPane.showMessageDialog(null,"Profile successfully updated");
t1.setText("");
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}
}
);
b2.addActionListener(
a->
{
new Home(username);
dispose();
}
);
setVisible(true);
setSize(800, 550);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Profile Settings");
}
public static void main(String[] args) {
new Profile("Swayam");
}
}