-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelete.java
More file actions
75 lines (60 loc) · 2.32 KB
/
Delete.java
File metadata and controls
75 lines (60 loc) · 2.32 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
class Delete {
static Connection con;
public static void main(String[] args) {
new Delete(12115299);
}
Delete(int uid)
{
try{
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Inventory", "root", "abhi1210@");
}
catch(Exception ex) { System.out.println(ex); }
Font bold = new Font("Serif",1,35);
Font plan = new Font("Serif",0,25);
JFrame df = new JFrame("DELETE ITEM");
df.setSize(400,400);
df.getContentPane().setBackground(new Color(0, 153, 153));
df.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
df.setLocationRelativeTo(null);
df.setLayout(null);
JLabel head = new JLabel("Delete Item",JLabel.CENTER);
head.setFont(bold);
JTextField id = new JTextField("Item Code*");
id.setFont(plan);
JButton delete = new JButton("DELETE");
delete.setFont(plan);
delete.setBackground(new Color(247,183,93));
df.add(head);df.add(id);df.add(delete);
head.setBounds(0,0,400,50);
id.setBounds(100,100,200,40);
delete.setBounds(100,300,200,40);
String tablename = "UIT"+uid;
class MyListener implements ActionListener {
public void actionPerformed(ActionEvent ae) {
String id_ = id.getText();
try {
PreparedStatement ps = con.prepareStatement("delete from "+tablename+" where ITEM_ID = ?");
ps.setString(1,id_);
int n = ps.executeUpdate();
if(n>0) {
System.out.println("Deleted");
JOptionPane.showMessageDialog(df, "Item Deleted Successfully! ");
}
else{
JOptionPane.showMessageDialog(df, "Item is Not Present!!");
}
} catch (Exception exc) {
System.out.println(exc);
}
}
}
MyListener ml = new MyListener();
delete.addActionListener(ml);
df.setVisible(true);
}
}