Repository navigation
Expand file tree
/
Copy pathsearch.java
More file actions
152 lines (125 loc) · 4.36 KB
/
Copy pathsearch.java
File metadata and controls
152 lines (125 loc) · 4.36 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class search implements ActionListener
{
public static JFrame f=new JFrame("Search Book");
public static Container c=f.getContentPane();
public static JLabel bookid,bookname,bookprice,publisher,pages,searching;
public static JTextField idtxt,nametxt,pricetxt,publishertxt,pagetxt;
public static JButton search,exit,issue;
//public static String username;
search()
{
f.setBounds(440,100,400,500);
c.setBackground(new Color(100,200,10,109));
f.setLayout(null);
searching=new JLabel("SEARCHING BOOK.....");
searching.setBounds(60,10,150,50);
f.add(searching);
searching.setForeground(Color.red);
bookid=new JLabel("BookID : ");
bookid.setBounds(60,100,100,20);
f.add(bookid);
idtxt=new JTextField();
idtxt.setBounds(130,100,150,30);
f.add(idtxt);
bookname=new JLabel("Name : ");
bookname.setBounds(60,150,100,20);
f.add(bookname);
nametxt=new JTextField();
nametxt.setBounds(130,150,150,30);
f.add(nametxt);
bookprice=new JLabel("price : ");
bookprice.setBounds(60,250,100,20);
f.add(bookprice);
pricetxt=new JTextField();
pricetxt.setBounds(130,250,150,30);
f.add(pricetxt);
publisher=new JLabel("Publisher : ");
publisher.setBounds(60,200,100,20);
f.add(publisher);
publishertxt=new JTextField();
publishertxt.setBounds(130,200,150,30);
f.add(publishertxt);
pages=new JLabel("Pages : ");
pages.setBounds(60,300,100,20);
f.add(pages);
pagetxt=new JTextField();
pagetxt.setBounds(130,300,150,30);
f.add(pagetxt);
search=new JButton("Search");
search.setBounds(30,400,100,30);
f.add(search);
search.setBackground(Color.blue);
search.setForeground(Color.white);
issue=new JButton("Issue");
issue.setBounds(250,400,100,30);
f.add(issue);
issue.setBackground(Color.blue);
issue.setForeground(Color.white);
exit=new JButton("Exit");
exit.setBounds(140,400,100,30);
f.add(exit);
exit.setBackground(Color.red);
exit.setForeground(Color.white);
search.addActionListener(this);
issue.addActionListener(this);
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
f.setVisible(true);
exit.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e1)
{
System.exit(0);
}
});
}
public static void main(String args[])
{
new search();
}
@Override
public void actionPerformed(ActionEvent e2)
{
String bookId=idtxt.getText();
String name,page,price,publisher;
try
{
Connection conn;
conn=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/library","root","sagarmatha0school");
if(e2.getSource()==search)
{
PreparedStatement pre=conn.prepareStatement("Select * from book where id='"+bookId+"' ");
ResultSet rs=pre.executeQuery();
if(rs.next())
{
name=rs.getString(2);
price=rs.getString(4);
publisher=rs.getString(3);
page=rs.getString(5);
nametxt.setText(name);
publishertxt.setText(publisher);
pricetxt.setText(price);
pagetxt.setText(price);
}
else
{
JOptionPane.showMessageDialog(f,"No Book Found");
pre.close();
rs.close();
}
}
if(e2.getSource()==issue)
{
new issue();
}
conn.close();
}catch(Exception exe)
{
}
}
}