-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewStudentDetails.java
145 lines (136 loc) · 4.88 KB
/
ViewStudentDetails.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
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTable;
import javax.swing.JButton;
import javax.swing.JComboBox;
import net.proteanit.sql.DbUtils;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
class ViewStudentDetails extends JFrame implements ActionListener
{
JComboBox rollNoComboBox;
JTable table;
JButton searchBtn, printBtn, updateBtn,addBtn, backBtn;
JLabel searchLabel;
String[] rollNoList;
ResultSet rs;
Connection c;
Statement st;
JScrollPane scrollPane;
ViewStudentDetails()
{
this.setLayout(null);
searchLabel=new JLabel("Select Rollno to Search:");
searchLabel.setBounds(80, 50, 250, 30);
searchLabel.setFont(new Font("serif", Font.BOLD, 20));
this.add(searchLabel);
rollNoList=getRollNoFromDB();
rollNoComboBox=new JComboBox(rollNoList);
rollNoComboBox.setBounds(320,50,150,30);
rollNoComboBox.addActionListener(this);
this.add(rollNoComboBox);
searchBtn=new JButton("Search");
searchBtn.setBackground(Color.WHITE);
searchBtn.setForeground(Color.BLACK);
searchBtn.setBounds(500,50,120,30);
searchBtn.setFont(new Font("serif", Font.PLAIN, 25));
searchBtn.addActionListener(this);
this.add(searchBtn);
backBtn=new JButton("Back");
backBtn.setBackground(Color.WHITE);
backBtn.setForeground(Color.BLACK);
backBtn.setBounds(650,50,120,30);
// backBtn.setBounds(640,120,100,30);
backBtn.setFont(new Font("serif", Font.PLAIN, 25));
backBtn.addActionListener(this);
this.add(backBtn);
this.setSize(1000,750);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
String[] getRollNoFromDB()
{
String[] a;
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/universitymanagementsystem", "root", "root");
//name varchar(30), fatherName varchar(30),rollNo varchar (10),dob varchar(40),address varchar(100),phone varchar(30),email varchar(20),classX varchar(30),classXII varchar(30),aadhar varchar(30),course varchar(30),branch varchar(30));
Statement st=c.createStatement();
String selectAllQuery="select rollNo from student;";
rs=st.executeQuery(selectAllQuery);
ArrayList<String> s=new ArrayList<>();
int size=0;
while (rs.next())
{
size++;
s.add(rs.getString(1));
}
a=new String[size];
for(int i =0;i<size;i++)
{
a[i] = s.get(i);
}
c.close();
return a;
}
catch (Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(null, e.toString());
}
a=null;
return a;
}
public void StudentDetailsTable()
{
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
c = DriverManager.getConnection("jdbc:mysql://localhost:3306/universitymanagementsystem", "root", "root");
st=c.createStatement();
String selectQuery="select *from student where rollNo='"+(String)rollNoComboBox.getSelectedItem()+"';";
rs=st.executeQuery(selectQuery);
table =new JTable();
table.setModel(DbUtils.resultSetToTableModel(rs));
table.setBounds(10,160,950,400);
table.setFont(new Font("serif", Font.PLAIN, 15));
scrollPane=new JScrollPane(table);
scrollPane.setBounds(10, 160, 950, 300);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
this.add(scrollPane);
c.close();
}
catch (Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(null, e.toString());
}
}
public void actionPerformed(ActionEvent a)
{
if(a.getSource()==searchBtn)
{
StudentDetailsTable();
}
else if(a.getSource()==backBtn)
{
this.setVisible(false);
}
}
public static void main(String[] args)
{
new ViewStudentDetails();
}
}