-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reportcourse.java
83 lines (72 loc) · 2.69 KB
/
Reportcourse.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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class Reportcourse extends JFrame implements ActionListener
{
JTextArea ta;
JScrollPane jsp;
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
Container c = getContentPane();
JButton display,ok;
JPanel p1,p2;
Reportcourse()
{
setLayout(null);
setSize(800,800);
display = new JButton("Display");
display.setBounds(320,10,120,30);
add(display);
ok = new JButton("OK");
ok.setBounds(320,460,120,30);
add(ok);
ta = new JTextArea();
jsp = new JScrollPane(ta,v,h);
jsp.setBounds(50,50,700,350);
c.add(jsp);
ta.setEditable(false);
setVisible(true);
display.addActionListener(this);
ok.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==display)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection c=DriverManager.getConnection("jdbc:mysql://localhost:3306/institute","root","root");
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("select * from Teacher");
ResultSetMetaData md = rs.getMetaData();
int n = md.getColumnCount();
for(int i=1;i<=n;i++)
{
ta.append(md.getColumnName(i)+"\t");
}
ta.append("\n\n");
while(rs.next())
{
for(int i=1;i<=n;i++)
{
ta.append(rs.getString(i)+"\t");
}
ta.append("\n");
}
}
catch(Exception a)
{
}
}
if(ae.getSource()==ok)
{
setVisible(false);
}
}
public static void main(String a[])
{
new Reportcourse();
}
}