-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlip28B.java
More file actions
119 lines (84 loc) · 2.67 KB
/
Slip28B.java
File metadata and controls
119 lines (84 loc) · 2.67 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
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
//Q) Write a java program to display the selected employee details in JTable. (use database, combo box for employee //selection ) Employee having fields eno, ename, sal, desg.
//CODE
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class Slip28B extends JFrame implements ActionListener
{
private JLabel lblEid;
private JComboBox empId;
private JTable empTable;
private JButton btnShow;
private JPanel inputPanel;
Connection con=null;
Statement stmt;
public Slip28B() throws SQLException,ClassNotFoundException
{
setTitle( "Employees" );
setSize( 500, 300 );
setBackground( Color.gray );
inputPanel = new JPanel(new FlowLayout());
lblEid = new JLabel("Select Employee Id : ");
empId = new JComboBox();
btnShow = new JButton("Display Record");
btnShow.addActionListener(this);
inputPanel.add(lblEid);
inputPanel.add(empId);
inputPanel.add(btnShow);
add(inputPanel);
//populating combo box with EmpId
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:dsn1");
stmt = con.createStatement();
String query = "Select * from bookm";
ResultSet rs = stmt.executeQuery(query);
while(rs.next())
empId.addItem(rs.getString(1)); // book id
//empId.addItem(rs.getString(1) + rs.getString(2));
//empId.addItem(rs.getString(2)) book name
empTable = new JTable(10,4);
rs.close();
stmt.close();
con.close();
}
public void actionPerformed(ActionEvent ae)
{
int i=0;
try
{
String id = empId.getSelectedItem().toString(); //important
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:dsn1");
stmt = con.createStatement();
String query = "Select * from bookm where bname=" + id;
//String query = "Select * from bookm";// where bno=" + id;
ResultSet rs = stmt.executeQuery(query);
// Create a new table instance
while(rs.next())
{
empTable .setValueAt(rs.getString(1),i,0);
empTable .setValueAt(rs.getString(2),i,1);
empTable .setValueAt(rs.getString(3),i,2);
empTable .setValueAt(rs.getString(4),i,3);
i++;
}
rs.close();
stmt.close();
con.close();
inputPanel.add(new JScrollPane(empTable));
validate();
repaint();
}
catch(Exception se)
{
System.out.println(se);
}
}
public static void main( String args[] ) throws SQLException,ClassNotFoundException
{
Slip28B obj = new Slip28B();
obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
obj.setVisible( true );
}
}