-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.java
More file actions
67 lines (59 loc) · 1.96 KB
/
Copy pathview.java
File metadata and controls
67 lines (59 loc) · 1.96 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class view extends JFrame{
Container c;
TextArea taData;
JButton btnBack;
view(){
c = getContentPane();
c.setLayout(new FlowLayout(FlowLayout.CENTER,20,20));
taData = new TextArea(12,30);
taData.setEditable(false);
btnBack = new JButton("Back to Main");
Font f = new Font("Times New Roman",Font.PLAIN,20);
Font t = new Font("Times New Roman",Font.BOLD,20);
taData.setFont(f);
btnBack.setFont(t);
c.add(taData);
c.add(btnBack);
class Eh1 implements ActionListener{
public void actionPerformed(ActionEvent ae){
dashboard a = new dashboard();
dispose();
}
}
btnBack.addActionListener(new Eh1());
String user = System.getenv("DB_USER");
String pwd = System.getenv("DB_PASSWORD");
String url = "jdbc:mysql://localhost:3306/student_db";
taData.setText("Name\tRollno\tCourse\t\tMarks\n");
taData.append("-------------------------------------------------------------\n");
try{
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
try(Connection con = DriverManager.getConnection(url,user,pwd);
PreparedStatement pst = con.prepareStatement("select * from student");
ResultSet rs = pst.executeQuery()){
while (rs.next()) {
int rno = rs.getInt("rno");
String name = rs.getString("name");
int marks = rs.getInt("marks");
String course = rs.getString("course");
taData.append(name + "\t\t" + rno + "\t\t" + course + "\t\t" + marks +"\n");
}
} catch(SQLException e){
String msg = "issue " + e;
JOptionPane.showMessageDialog(c,msg);
}
} catch(SQLException e){
String msg = "issue " + e;
JOptionPane.showMessageDialog(c,msg);
}
setSize(500,450);
setLocationRelativeTo(null);
setTitle("Database");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}