-
Notifications
You must be signed in to change notification settings - Fork 0
/
courecd.java
259 lines (201 loc) · 7.07 KB
/
courecd.java
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.swing.table.*;
import java.sql.*;
import java.sql.ResultSet;
class courecd extends JFrame implements ActionListener
{
JLabel ladm,lcoid,lconm,lcopd,ltnm,lcof,lcof1;
JTextField tcoid,tconm,tcopd,ttnm,tcof,tcof1;
JButton bopen,bdel,bcle,bcan;
Font fo=new Font("Verdana" ,Font.BOLD,20);
Connection con;
ResultSet rs;
Statement stmt;
PreparedStatement pst;
//Table
DefaultTableModel model = new DefaultTableModel();
JTable tabGrid = new JTable(model);
JScrollPane scrlPane = new JScrollPane(tabGrid);
courecd()
{
setSize(420,560);
setVisible(true);
setLayout(null);
setTitle(" COURSE RECORD");
setResizable(false);
setLocation(300,160);
ladm=new JLabel("DELETE COURSE");
ladm.setBounds(130,30,270,30);
ladm.setFont(fo);
ladm.setForeground(Color.red);
lcoid=new JLabel("Course Id :");
lcoid.setBounds(20,90,110,30);
tcoid=new JTextField(5);
tcoid.setBounds(150,90,90,25);
lconm=new JLabel("Course Name :");
lconm.setBounds(20,140,110,30);
tconm=new JTextField(25);
tconm.setBounds(150,140,90,25);
lcopd=new JLabel("Course Period:");
lcopd.setBounds(20,190,110,25);
tcopd=new JTextField(30);
tcopd.setBounds(150,190,90,25);
lcof=new JLabel("Onetime Fees :");
lcof.setBounds(20,240,110,25);
tcof=new JTextField(20);
tcof.setBounds(150,240,90,25);
lcof1=new JLabel("Installment Fees:");
lcof1.setBounds(20,290,140,25);
tcof1=new JTextField(20);
tcof1.setBounds(150,290,90,25);
bopen=new JButton("Open");
bopen.setBounds(15,340,80,25);
bopen.addActionListener(this);
bdel=new JButton("Delete");
bdel.addActionListener(this);
bdel.setBounds(113,340,90,25);
bcle=new JButton("Clear");
bcle.addActionListener(this);
bcle.setBounds(220,340,80,25);
bcan=new JButton("ALL");
bcan.addActionListener(this);
bcan.setBounds(315,340,80,25);
add(ladm);
add(lcoid);
add(tcoid);
add(lconm);
add(tconm);
add(lcopd);
add(tcopd);
add(lcof);
add(tcof);
add(lcof1);
add(tcof1);
add(bopen);
add(bcle);
add(bdel);
add(bcan);
tcoid.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))))
{
JOptionPane.showMessageDialog(null, "Please enter a numerical value");
e.consume();
}
}
});
// Table
scrlPane.setBounds(0,390,418,200);
add(scrlPane);
tabGrid.setFont(new Font ("Verdana",0,13));
model.addColumn("C_ID");
model.addColumn("C_NAME");
model.addColumn("C_PERIOD");
model.addColumn("O_FEE");
model.addColumn("I_FEE");
tconm.setEnabled(false);
tcopd.setEnabled(false);
tcof.setEnabled(false);
tcof1.setEnabled(false);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==bopen)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con= DriverManager.getConnection("jdbc:mysql://localhost:3306/institute","root","root");
stmt= con.createStatement();
String id=tcoid.getText();
String qry= "select * from Course where co_id="+id+"";
rs = stmt.executeQuery(qry);
while(rs.next())
{
tconm.setText(rs.getString(2));
tcopd.setText(rs.getString(3));
tcof.setText(rs.getString(4));
tcof1.setText(rs.getString(5));
tconm.setEnabled(true);
tcopd.setEnabled(true);
tcof.setEnabled(true);
tcof1.setEnabled(true);
}
con.close();
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,"Error Occured : " + ex);
}
}
if(ae.getSource()==bcle)
{
tcoid.setText(" ");
tconm.setText(" ");
tcopd.setText(" ");
tcof.setText(" ");
tcof1.setText(" ");
tconm.setEnabled(false);
tcopd.setEnabled(false);
tcof.setEnabled(false);
tcof1.setEnabled(false);
}
if(ae.getSource()==bcan)
{
int r = 0;
while(model.getRowCount() > 0)
{
model.removeRow(0);
}
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection cnDriver = DriverManager.getConnection("jdbc:mysql://localhost:3306/institute","root","root");
Statement stmt = cnDriver.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT * from Course" );
while(rs.next())
{
model.insertRow(r++, new Object[]{rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5) });
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,"Error Occured : " + ex);
}
}
if(ae.getSource()==bdel)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/institute","root","root");
pst=con.prepareStatement("Delete from Course where co_id=?");
String coid1=tcoid.getText();
pst.setString(1,coid1);
JOptionPane.showMessageDialog(null,"Record Is Deleted ");
pst.executeUpdate();
tcoid.setText("");
tconm.setText("");
tcopd.setText("");
tcof.setText("");
tcof1.setText(" ");
con.close();
}
catch(Exception ex)
{
System.out.println("Error occured :"+ex);
}
}
}
public static void main (String args[])
{
new courecd();
}
}