-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue.java
149 lines (123 loc) · 4.38 KB
/
issue.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
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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class issue 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;
public static JButton exit,issue;
//public static String username;
issue()
{
f.setBounds(440,150,400,350);
c.setBackground(new Color(100,200,10,109));
f.setLayout(null);
searching=new JLabel("Issue BOOK.....");
searching.setBounds(60,10,150,50);
f.add(searching);
searching.setForeground(Color.red);
bookid=new JLabel("Username : ");
bookid.setBounds(60,100,100,20);
f.add(bookid);
idtxt=new JTextField();
idtxt.setBounds(130,100,150,30);
f.add(idtxt);
bookname=new JLabel("BookId : ");
bookname.setBounds(60,150,100,20);
f.add(bookname);
nametxt=new JTextField();
nametxt.setBounds(130,150,150,30);
f.add(nametxt);
bookprice=new JLabel("BookName : ");
bookprice.setBounds(60,200,100,20);
f.add(bookprice);
pricetxt=new JTextField();
pricetxt.setBounds(130,200,150,30);
f.add(pricetxt);
issue=new JButton("Issue");
issue.setBounds(60,250,100,30);
f.add(issue);
issue.setBackground(Color.blue);
issue.setForeground(Color.white);
exit=new JButton("Exit");
exit.setBounds(180,250,100,30);
f.add(exit);
exit.setBackground(Color.red);
exit.setForeground(Color.white);
issue.addActionListener(this);
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
f.setVisible(true);
f.setResizable(false);
exit.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e1)
{
System.exit(0);
}
});
}
public static void main(String args[])
{
new issue();
}
@Override
public void actionPerformed(ActionEvent e2)
{
String bookId=idtxt.getText();
String name,price;
name=nametxt.getText();
price=pricetxt.getText();
if(name.isEmpty()|| bookId.isEmpty()|| price.isEmpty())
{
JOptionPane.showMessageDialog(f,"Fill the Credentials..");
}
else
{
try
{
//creating connection
Connection conn;
conn=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/library","root","sagarmatha0school");
//creare statement
// first check whether the username already exist or not
PreparedStatement p1=conn.prepareStatement("select * from studentdetail where username='"+bookId+"'");
ResultSet r1=p1.executeQuery();
if(r1.next())//checking username
{
PreparedStatement pcheck=conn.prepareStatement("select * from book where id='"+name+"' ");
ResultSet rs=pcheck.executeQuery();
if(rs.next()) //checking bookid
{
PreparedStatement ps=conn.prepareStatement("insert into issuedbook values(?,?,?)");
// ResultSet rs=ps.executeQuery();
ps.setString(1, bookId);
ps.setString(2,name);
ps.setString(3,price);
int i=ps.executeUpdate();
conn.close();
ps.close();
JOptionPane.showMessageDialog(f,"Issued Successfully..");
f.setVisible(false);
}
else //else insert into database.
{
JOptionPane.showMessageDialog(f,"No Book For This ID Found !");
// student_login lp=new student_login (); //calling the login page
}
}
else
{
JOptionPane.showMessageDialog(f,"Invalid Username");
}
}catch(Exception ep)
{
System.err.println(ep);
}
}
}
}