-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathViewStudent.java
More file actions
64 lines (55 loc) · 1.7 KB
/
ViewStudent.java
File metadata and controls
64 lines (55 loc) · 1.7 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
package GUI;
import java.awt.GridLayout;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import Business.StudentDB;
public class ViewStudent extends JFrame {
Vector vData=null, vTitle=null;
ResultSet rs;
ResultSetMetaData rstmeta;
JFrame f = new JFrame("View Student");
public ViewStudent() {
f.setLocation(300, 300);
f.setLayout(new GridLayout(2,1));
StudentDB s = new StudentDB();
rs = s.SelectDB("Select * from Student");
try {
rstmeta = rs.getMetaData();
int num_column = rstmeta.getColumnCount();
/*Chuẩn bị dữ liệu để tạo bảng (JTable) hiển thị thông tin
vTitle chứa đựng thông tin tên cột của bảng */
vTitle = new Vector(num_column);
for (int i=1; i<=num_column;i++)
{
vTitle.add(rstmeta.getColumnLabel(i));
}
vData = new Vector(10,10);
while (rs.next())
{
Vector row = new Vector(num_column);
for (int i=1; i<=num_column;i++)
row.add(rs.getString(i));
vData.add(row);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*tạo bảng để chứa thông tin truy vấn từ csdl*/
JScrollPane tableResult = new JScrollPane(new JTable(vData,vTitle));
f.setSize(200 , 200);
f.setContentPane(tableResult);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new ViewStudent();
}
}