-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewIssuedBook.java
111 lines (81 loc) · 2.65 KB
/
ViewIssuedBook.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
package BookClasses;
import AdminClasses.AdminLoged;
import DbClasses.DB;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import javax.swing.*;
public class ViewIssuedBook extends JFrame{
static ViewIssuedBook frame;
private JTable table ;
public static void main(String []args)
{
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try{
frame = new ViewIssuedBook();
frame.setVisible(true);
}catch (Exception e)
{
e.printStackTrace();
}
}
});
}
public ViewIssuedBook()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(200,80,880,550);
setTitle("Issued Books Database");
String data[][] = null;
String column[] = null;
try{
Connection con = DB.getConnection();
PreparedStatement ps = con.prepareStatement("select * from issuebooks", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = ps.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
column = new String[cols];
for (int i=1; i<=cols; i++)
{
column[i-1] = rsmd.getColumnName(i);
}
rs.last();
int rows = rs.getRow();
rs.beforeFirst();
data = new String[rows][cols];
int count = 0;
while(rs.next())
{
for (int i=1; i<=cols; i++)
{
data[count][i-1] = rs.getString(i);
}
count++;
}
con.close();
}catch (Exception e)
{
System.out.println(e);
}
JButton btnback = new JButton("Back");
btnback.setBounds(720,430,100,40);
add(btnback);
btnback.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
AdminLoged.main(new String[]{});
frame.dispose();
}
});
table = new JTable(data, column);
JScrollPane sp = new JScrollPane(table);
table.setBackground(Color.orange);
add(sp);
}
}