-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjcrud.java
More file actions
198 lines (167 loc) · 5.64 KB
/
jcrud.java
File metadata and controls
198 lines (167 loc) · 5.64 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import java.awt.EventQueue;
import java.sql.*;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.BorderLayout;
import java.awt.Font;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import java.awt.Color;
import javax.swing.border.EtchedBorder;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class jcrud {
private JFrame frame;
private JTextField txtname;
private JTextField txtedition;
private JTextField txtprice;
private JTable table;
private JTextField textid;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
jcrud window = new jcrud();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public jcrud() {
initialize();
Connect();
}
Connection con;
PreparedStatement pat;
public void Connect()
{
try {
Class.forName("org.sqlite.JDBC");
Connection con =DriverManager.getConnection("jdbc:sqlite:F:\\sql lite\\SQLiteStudio\\BOOKSTORE");
}
catch (ClassNotFoundException ex)
{
}
catch (SQLException ex)
{
}
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 648, 350);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel lblNewLabel = new JLabel("BOOK SHOP");
lblNewLabel.setFont(new Font("Times New Roman", Font.BOLD, 29));
lblNewLabel.setBounds(151, 11, 212, 25);
frame.getContentPane().add(lblNewLabel);
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "REGISTRAION", TitledBorder.LEADING, TitledBorder.TOP, null, Color.RED));
panel.setBounds(35, 61, 342, 139);
frame.getContentPane().add(panel);
panel.setLayout(null);
JLabel lblNewLabel_1 = new JLabel("EDITION");
lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1.setBounds(10, 60, 73, 14);
panel.add(lblNewLabel_1);
JLabel lblNewLabel_1_1 = new JLabel("BOOK NAME");
lblNewLabel_1_1.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1_1.setBounds(10, 33, 88, 14);
panel.add(lblNewLabel_1_1);
JLabel lblNewLabel_1_2 = new JLabel("PRICE");
lblNewLabel_1_2.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1_2.setBounds(10, 89, 73, 14);
panel.add(lblNewLabel_1_2);
txtname = new JTextField();
txtname.setBounds(154, 32, 162, 20);
panel.add(txtname);
txtname.setColumns(10);
txtedition = new JTextField();
txtedition.setColumns(10);
txtedition.setBounds(154, 59, 162, 20);
panel.add(txtedition);
txtprice = new JTextField();
txtprice.setColumns(10);
txtprice.setBounds(154, 88, 162, 20);
panel.add(txtprice);
JButton btnNewButton = new JButton("SAVE");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String bname,edition,price;
bname=txtname.getText();
edition=txtedition.getText();
price=txtprice.getText();
try {
pat =con.prepareStatement("insert into BOOKSTORE(name,edition,price)values(?,?,?");
pat.setString(1, bname);
pat.setString(1, edition);
pat.setString(1, price);
pat.executeUpdate();
JOptionPane.showMessageDialog(null,"Record Added !!!!!!!!!!!!!!!");
// table_load();
txtname.setText("");
txtedition.setText("");
txtprice.setText("");
txtname.requestFocus();
}
catch (SQLException el) {
el.printStackTrace();
}
}
});
btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 13));
btnNewButton.setBounds(35, 212, 103, 37);
frame.getContentPane().add(btnNewButton);
JButton btnExit = new JButton("EXIT");
btnExit.setFont(new Font("Tahoma", Font.BOLD, 13));
btnExit.setBounds(154, 211, 103, 37);
frame.getContentPane().add(btnExit);
JButton btnClear = new JButton("CLEAR");
btnClear.setFont(new Font("Tahoma", Font.BOLD, 13));
btnClear.setBounds(274, 211, 103, 37);
frame.getContentPane().add(btnClear);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(387, 61, 235, 187);
frame.getContentPane().add(scrollPane);
table = new JTable();
scrollPane.setViewportView(table);
JPanel panel_1 = new JPanel();
panel_1.setBorder(new TitledBorder(null, "SEARCH", TitledBorder.LEADING, TitledBorder.TOP, null, Color.RED));
panel_1.setBounds(35, 255, 342, 45);
frame.getContentPane().add(panel_1);
panel_1.setLayout(null);
JLabel lblNewLabel_1_3 = new JLabel("BOOK ID");
lblNewLabel_1_3.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1_3.setBounds(10, 15, 89, 19);
panel_1.add(lblNewLabel_1_3);
textid = new JTextField();
textid.setColumns(10);
textid.setBounds(154, 14, 162, 20);
panel_1.add(textid);
JButton btnUpdate = new JButton("UPDATE");
btnUpdate.setFont(new Font("Tahoma", Font.BOLD, 13));
btnUpdate.setBounds(387, 263, 103, 37);
frame.getContentPane().add(btnUpdate);
JButton btnDelete = new JButton("DELETE");
btnDelete.setFont(new Font("Tahoma", Font.BOLD, 13));
btnDelete.setBounds(507, 263, 103, 37);
frame.getContentPane().add(btnDelete);
}
}