├── deptable.java
├── JAVATASK.java
├── DBConnect.java
├── department.form
└── department.java
/deptable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4 | */
5 | package javatask;
6 |
7 | /**
8 | *
9 | * @author Rw
10 | */
11 | class deptable {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/JAVATASK.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
4 | */
5 | package javatask;
6 |
7 | /**
8 | *
9 | * @author Rw
10 | */
11 | public class JAVATASK {
12 |
13 | /**
14 | * @param args the command line arguments
15 | */
16 | public static void main(String[] args) {
17 | // TODO code application logic here
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/DBConnect.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4 | */
5 | package javatask;
6 |
7 | /**
8 | *
9 | * @author Rw
10 | */
11 | import java.sql.*;
12 | public class DBConnect {
13 | public static void main(String args[]){
14 | try{
15 | //step1 load the driver class
16 | Class.forName("com.mysql.cj.jdbc.Driver");
17 | //step2 create the connection object
18 | Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Department","root","NKaviya@2003");
19 | //step3 create the statement object
20 | Statement stmt=con.createStatement();
21 | //step4 execute query
22 | //ResultSet rs=stmt.executeQuery("create table employee (empid number(4), empname varchar2(25))");
23 | stmt.executeUpdate("insert into dep_info values(4, 'IT')");
24 | stmt.executeUpdate("update dep_info set dep_name='IT' where dep_code=3");
25 | //ResultSet rs=stmt.executeQuery("select * from employee");
26 | //while(rs.next())
27 | //System.out.println(rs.getInt(1)+" "+rs.getString(2));
28 | //ResultSet rs=stmt.executeQuery("delete from employee");
29 | //step5 close the connection object
30 |
31 | }catch(Exception e){ System.out.println(e);}
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/department.form:
--------------------------------------------------------------------------------
1 |
2 |
3 |
285 |
--------------------------------------------------------------------------------
/department.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3 | * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
4 | */
5 | package javatask;
6 |
7 | /**
8 | *
9 | * @author Rw
10 | */
11 | import java.sql.*;
12 | import javax.swing.table.DefaultTableModel;
13 | public class department extends javax.swing.JFrame {
14 |
15 |
16 | /**
17 | * Creates new form department
18 | */
19 | public department() {
20 | initComponents();
21 | }
22 |
23 | /**
24 | * This method is called from within the constructor to initialize the form.
25 | * WARNING: Do NOT modify this code. The content of this method is always
26 | * regenerated by the Form Editor.
27 | */
28 | @SuppressWarnings("unchecked")
29 | // //GEN-BEGIN:initComponents
30 | private void initComponents() {
31 |
32 | jButton2 = new javax.swing.JButton();
33 | jPanel1 = new javax.swing.JPanel();
34 | jLabel1 = new javax.swing.JLabel();
35 | jPanel2 = new javax.swing.JPanel();
36 | LISTDEP = new javax.swing.JButton();
37 | edit = new javax.swing.JButton();
38 | jPanel3 = new javax.swing.JPanel();
39 | jScrollPane1 = new javax.swing.JScrollPane();
40 | deptable = new javax.swing.JTable();
41 | jLabel2 = new javax.swing.JLabel();
42 | jLabel3 = new javax.swing.JLabel();
43 | depid = new javax.swing.JTextField();
44 | depName = new javax.swing.JTextField();
45 | addButton = new javax.swing.JButton();
46 | update = new javax.swing.JButton();
47 | delete = new javax.swing.JButton();
48 |
49 | jButton2.setText("jButton2");
50 |
51 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
52 |
53 | jPanel1.setBackground(new java.awt.Color(204, 255, 255));
54 |
55 | jLabel1.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
56 | jLabel1.setText("M KUMARASAMY COLLEGE OF ENGINEERING");
57 |
58 | javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
59 | jPanel1.setLayout(jPanel1Layout);
60 | jPanel1Layout.setHorizontalGroup(
61 | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
62 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
63 | .addGap(0, 0, Short.MAX_VALUE)
64 | .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE))
65 | );
66 | jPanel1Layout.setVerticalGroup(
67 | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
68 | .addGroup(jPanel1Layout.createSequentialGroup()
69 | .addGap(22, 22, 22)
70 | .addComponent(jLabel1)
71 | .addContainerGap(28, Short.MAX_VALUE))
72 | );
73 |
74 | jPanel2.setBackground(new java.awt.Color(204, 204, 255));
75 |
76 | LISTDEP.setText("LISTALL");
77 | LISTDEP.addActionListener(new java.awt.event.ActionListener() {
78 | public void actionPerformed(java.awt.event.ActionEvent evt) {
79 | LISTDEPActionPerformed(evt);
80 | }
81 | });
82 |
83 | edit.setText("EDIT");
84 | edit.addActionListener(new java.awt.event.ActionListener() {
85 | public void actionPerformed(java.awt.event.ActionEvent evt) {
86 | editActionPerformed(evt);
87 | }
88 | });
89 |
90 | javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
91 | jPanel2.setLayout(jPanel2Layout);
92 | jPanel2Layout.setHorizontalGroup(
93 | jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
94 | .addGroup(jPanel2Layout.createSequentialGroup()
95 | .addContainerGap()
96 | .addComponent(LISTDEP, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
97 | .addContainerGap(19, Short.MAX_VALUE))
98 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
99 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
100 | .addComponent(edit, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
101 | .addContainerGap())
102 | );
103 | jPanel2Layout.setVerticalGroup(
104 | jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
105 | .addGroup(jPanel2Layout.createSequentialGroup()
106 | .addGap(54, 54, 54)
107 | .addComponent(LISTDEP)
108 | .addGap(89, 89, 89)
109 | .addComponent(edit)
110 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
111 | );
112 |
113 | jPanel3.setBackground(new java.awt.Color(255, 204, 255));
114 |
115 | deptable.setModel(new javax.swing.table.DefaultTableModel(
116 | new Object [][] {
117 | {null, null},
118 | {null, null},
119 | {null, null},
120 | {null, null}
121 | },
122 | new String [] {
123 | "DEP_ID", "DEP_NAME"
124 | }
125 | ));
126 | jScrollPane1.setViewportView(deptable);
127 |
128 | jLabel2.setText("DEP ID");
129 |
130 | jLabel3.setText("DEP NAME");
131 |
132 | depName.setText("\n\n");
133 | depName.addActionListener(new java.awt.event.ActionListener() {
134 | public void actionPerformed(java.awt.event.ActionEvent evt) {
135 | depNameActionPerformed(evt);
136 | }
137 | });
138 |
139 | addButton.setText("ADD");
140 | addButton.addActionListener(new java.awt.event.ActionListener() {
141 | public void actionPerformed(java.awt.event.ActionEvent evt) {
142 | addButtonActionPerformed(evt);
143 | }
144 | });
145 |
146 | update.setText("UPDATE");
147 | update.addActionListener(new java.awt.event.ActionListener() {
148 | public void actionPerformed(java.awt.event.ActionEvent evt) {
149 | updateActionPerformed(evt);
150 | }
151 | });
152 |
153 | delete.setText("DELETE");
154 | delete.addActionListener(new java.awt.event.ActionListener() {
155 | public void actionPerformed(java.awt.event.ActionEvent evt) {
156 | deleteActionPerformed(evt);
157 | }
158 | });
159 |
160 | javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
161 | jPanel3.setLayout(jPanel3Layout);
162 | jPanel3Layout.setHorizontalGroup(
163 | jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
164 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
165 | .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
166 | .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
167 | .addGap(34, 34, 34)
168 | .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
169 | .addGroup(jPanel3Layout.createSequentialGroup()
170 | .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
171 | .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
172 | .addComponent(jLabel3))
173 | .addGap(70, 70, 70)
174 | .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
175 | .addComponent(depid)
176 | .addComponent(depName)))
177 | .addGroup(jPanel3Layout.createSequentialGroup()
178 | .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
179 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
180 | .addComponent(update, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
181 | .addGap(55, 55, 55))))
182 | .addGroup(jPanel3Layout.createSequentialGroup()
183 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
184 | .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 299, javax.swing.GroupLayout.PREFERRED_SIZE)))
185 | .addGap(50, 50, 50)
186 | .addComponent(delete, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
187 | .addGap(74, 74, 74))
188 | );
189 | jPanel3Layout.setVerticalGroup(
190 | jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
191 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
192 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
193 | .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
194 | .addGap(37, 37, 37)
195 | .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
196 | .addComponent(jLabel2)
197 | .addComponent(depid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
198 | .addGap(54, 54, 54)
199 | .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
200 | .addComponent(jLabel3)
201 | .addComponent(depName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
202 | .addGap(54, 54, 54)
203 | .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
204 | .addComponent(addButton)
205 | .addComponent(update)
206 | .addComponent(delete))
207 | .addGap(70, 70, 70))
208 | );
209 |
210 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
211 | getContentPane().setLayout(layout);
212 | layout.setHorizontalGroup(
213 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
214 | .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
215 | .addGroup(layout.createSequentialGroup()
216 | .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
217 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
218 | .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
219 | );
220 | layout.setVerticalGroup(
221 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
222 | .addGroup(layout.createSequentialGroup()
223 | .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
224 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
225 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
226 | .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
227 | .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
228 | .addGap(0, 0, Short.MAX_VALUE))
229 | );
230 |
231 | pack();
232 | }// //GEN-END:initComponents
233 |
234 | private void LISTDEPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LISTDEPActionPerformed
235 | //TODO add your handling code here:
236 | listTable();
237 | }//GEN-LAST:event_LISTDEPActionPerformed
238 |
239 | private void depNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_depNameActionPerformed
240 | // TODO add your handling code here:
241 |
242 | }//GEN-LAST:event_depNameActionPerformed
243 |
244 | private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
245 | // TODO add your handling code here:
246 | int dcode= Integer.parseInt(depId.getTet());
247 | String dname = depName.getText();
248 | try{
249 | //step1 load the driver class
250 | Class.forName("com.mysql.cj.jdbc.Driver");
251 | //step2 create the connection object
252 | Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Department","root","NKaviya@2003");
253 | //step3 create the statement object
254 | Statement stmt=con.createStatement();
255 | //step4 execute query
256 | //ResultSet rs=stmt.executeQuery("create table employee (empid number(4), empname varchar2(25))");
257 | stmt.executeUpdate("insert into dep_info values("+dcode+",'"+dname+"')");
258 | //stmt.executeUpdate("update dep_info set dep_name='IT' where dep_code=3");
259 | //ResultSet rs=stmt.executeQuery("select * from employee");
260 | //while(rs.next())
261 | //System.out.println(rs.getInt(1)+" "+rs.getString(2));
262 | //stmt.executeUpdate("delete from dep_info where dep_id=3");
263 | //step5 close the connection object
264 | con.close();
265 | }catch(Exception e){ System.out.println(e);}
266 | depId.setText("");
267 | depName.setText("");
268 | listTable();
269 |
270 | }//GEN-LAST:event_addButtonActionPerformed
271 |
272 | private void editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editActionPerformed
273 | // TODO add your handling code here:
274 | DefaultTableModel model = (DefaultTableModel)deptable.getModel();
275 | int row=deptable.getSelectRow();
276 | depId.setText(model.getValueAt(row0).toString());
277 | depName.setText(model.getValueAt(row1).toString());
278 | }//GEN-LAST:event_editActionPerformed
279 |
280 | private void updateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateActionPerformed
281 | // TODO add your handling code here:
282 | int dcode= Integer.parseInt(depId.getText());
283 | String dname = depName.getText();
284 | try{
285 | //step1 load the driver class
286 | Class.forName("com.mysql.cj.jdbc.Driver");
287 | //step2 create the connection object
288 | Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/department", "root","NKaviya@2003");
289 | //step3 create the statement object
290 | Statement stmt=con.createStatement();
291 | stmt.executeUpdate("update dep_info set dep_name='"+dname+"' where dep_id="+dcode+"");
292 | con.close();
293 | }catch(Exception e){ System.out.println(e);}
294 | depId.setText("");
295 | depName.setText("");
296 | listTable();
297 | }//GEN-LAST:event_updateActionPerformed
298 |
299 | private void deleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteActionPerformed
300 | // TODO add your handling code here:
301 | int dcode= Integer.parseInt(depId.getText());
302 | String dname = depName.getText();
303 | try{
304 | //step1 load the driver class
305 | Class.forName("com.mysql.cj.jdbc.Driver");
306 | //step2 create the connection object
307 | Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/department", "root","NKaviya@2003");
308 | //step3 create the statement object
309 | Statement stmt=con.createStatement();
310 | stmt.executeUpdate("delete from dep_info where dep_id="+dcode+"");
311 | con.close();
312 | }catch(Exception e){ System.out.println(e);}
313 | depId.setText("");
314 | depName.setText("");
315 | listTable();
316 | }//GEN-LAST:event_deleteActionPerformed
317 |
318 |
319 | /**
320 | * @param args the command line arguments
321 | */
322 | public void listTable(){
323 | DefaultTableModel model = (DefaultTableModel)deptable.getModel();
324 | while(model.getRowCount()>0){
325 | for(int i=0;i
355 | /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
356 | * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
357 | */
358 | try {
359 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
360 | if ("Nimbus".equals(info.getName())) {
361 | javax.swing.UIManager.setLookAndFeel(info.getClassName());
362 | break;
363 | }
364 | }
365 | } catch (ClassNotFoundException ex) {
366 | java.util.logging.Logger.getLogger(Department.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
367 | } catch (InstantiationException ex) {
368 | java.util.logging.Logger.getLogger(Department.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
369 | } catch (IllegalAccessException ex) {
370 | java.util.logging.Logger.getLogger(Department.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
371 | } catch (javax.swing.UnsupportedLookAndFeelException ex) {
372 | java.util.logging.Logger.getLogger(Department.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
373 | }
374 | //
375 |
376 | /* Create and display the form */
377 | java.awt.EventQueue.invokeLater(new Runnable() {
378 | public void run() {
379 | new Department().setVisible(true);
380 | }
381 | });
382 | }
383 | //
384 |
385 | /* Create and display the form */
386 | java.awt.EventQueue.invokeLater(new Runnable() {
387 | public void run() {
388 | new department().setVisible(true);
389 | }
390 | });
391 | }
392 |
393 | // Variables declaration - do not modify//GEN-BEGIN:variables
394 | private javax.swing.JButton LISTDEP;
395 | private javax.swing.JButton addButton;
396 | private javax.swing.JButton delete;
397 | private javax.swing.JTextField depName;
398 | private javax.swing.JTextField depid;
399 | private javax.swing.JTable deptable;
400 | private javax.swing.JButton edit;
401 | private javax.swing.JButton jButton2;
402 | private javax.swing.JLabel jLabel1;
403 | private javax.swing.JLabel jLabel2;
404 | private javax.swing.JLabel jLabel3;
405 | private javax.swing.JPanel jPanel1;
406 | private javax.swing.JPanel jPanel2;
407 | private javax.swing.JPanel jPanel3;
408 | private javax.swing.JScrollPane jScrollPane1;
409 | private javax.swing.JButton update;
410 | // End of variables declaration//GEN-END:variables
411 | }
412 |
--------------------------------------------------------------------------------