-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewStudent.java
More file actions
105 lines (87 loc) · 3.13 KB
/
ViewStudent.java
File metadata and controls
105 lines (87 loc) · 3.13 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
package UniBuddy;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.sql.*;
import net.proteanit.sql.DbUtils;
public class ViewStudent extends JFrame implements ActionListener{
Choice studentRollNumber;
JTable studentTable;
JButton searchButton,printButton,updateButton,addButton,cancelButton;
ViewStudent(){
getContentPane().setBackground(Color.white);
setLayout(null);
JLabel headingViewStudent = new JLabel("Student Details");
headingViewStudent.setBounds(310, 30, 500, 50);
headingViewStudent.setFont(new Font("Sarif", Font.BOLD, 35)); /*awt*/
add(headingViewStudent);
JLabel heading = new JLabel("Search Student : ");
heading.setBounds(50, 100, 150, 20);
heading.setFont(new Font("Sarif", Font.PLAIN, 15));
add(heading);
studentRollNumber = new Choice();
studentRollNumber.setBounds(200, 100, 250, 20);
add(studentRollNumber);
try{
Conn c = new Conn();
ResultSet rs = c.s.executeQuery("select * from studentdetails");
while(rs.next()){
studentRollNumber.add(rs.getString("rollnumber"));
}
} catch (Exception e){
e.printStackTrace();
}
studentTable = new JTable();
try{
Conn c = new Conn();
ResultSet rs = c.s.executeQuery("select * from studentdetails");
studentTable.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception e){
e.printStackTrace();
}
JScrollPane jScroll = new JScrollPane(studentTable);
jScroll.setBounds(10, 200, 1400, 600);
add(jScroll);
searchButton = new JButton("Search");
searchButton.setBounds(50, 150, 70, 20);
searchButton.addActionListener(this);
add(searchButton);
printButton = new JButton("Print");
printButton.setBounds(150, 150, 70, 20);
printButton.addActionListener(this);
add(printButton);
addButton = new JButton("Cancel");
addButton.setBounds(250, 150, 70, 20);
addButton.addActionListener(this);
add(addButton);
setSize(900, 700);
setLocation(300, 100);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==searchButton){
String query = "select * from studentdetails where rollnumber = '"+studentRollNumber.getSelectedItem()+"'";
try {
Conn c = new Conn();
ResultSet rs = c.s.executeQuery(query);
studentTable.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception ae) {
ae.printStackTrace();
}
}
else if(e.getSource()==printButton){
try {
studentTable.print();
} catch (Exception ae) {
ae.printStackTrace();
}
}
else{
setVisible(false);
}
}
public static void main(String[] args) {
new ViewStudent();
}
}