└── JAVA
├── DBConnect.java
├── Department.form
├── Department.java
├── Javatask.java
└── ResultSet.java
/JAVA/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 | import java.sql.*;
7 | import java.sql.ResultSet;
8 | /**
9 | *
10 | * @author balak
11 | */
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","Bala@9344");
19 | //step3 create the statement object
20 | Statement stmt=con.createStatement();
21 |
22 | //step4 execute query
23 | //ResultSet rs=stmt.executeQuery("create table employee (empid number(4), empname varchar2(25))");
24 | //ResultSet rs=stmt.executeQuery("insert into employee values(1002, 'Rajesh')");
25 | // stmt.executeUpdate("update employee set empname=‘Aravind' where empid=120");
26 | ResultSet rs=stmt.executeQuery("select * from dep_info");
27 | while(rs.next())
28 | System.out.println(rs.getInt(1)+" "+rs.getString(2));
29 | //ResultSet rs=stmt.executeQuery("delete from employee");
30 | //step5 close the connection object
31 | con.close();
32 | }catch(Exception e){ System.out.println(e);
33 |
34 | }
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/JAVA/Department.form:
--------------------------------------------------------------------------------
1 |
2 |
3 |
189 |
--------------------------------------------------------------------------------
/JAVA/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 | import java.sql.*;
8 | import javax.swing.table.DefaultTableModel;
9 |
10 |
11 |
12 | /**
13 | *
14 | * @author balak
15 | */
16 | public class Department extends javax.swing.JFrame {
17 |
18 | /**
19 | * Creates new form Department
20 | */
21 | public Department() {
22 | initComponents();
23 | }
24 |
25 | /**
26 | * This method is called from within the constructor to initialize the form.
27 | * WARNING: Do NOT modify this code. The content of this method is always
28 | * regenerated by the Form Editor.
29 | */
30 | @SuppressWarnings("unchecked")
31 | // //GEN-BEGIN:initComponents
32 | private void initComponents() {
33 |
34 | jPanel1 = new javax.swing.JPanel();
35 | jLabel1 = new javax.swing.JLabel();
36 | jPanel2 = new javax.swing.JPanel();
37 | jScrollPane1 = new javax.swing.JScrollPane();
38 | table_dep = new javax.swing.JTable();
39 | jPanel3 = new javax.swing.JPanel();
40 | list_dep = new javax.swing.JButton();
41 |
42 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
43 |
44 | jPanel1.setBackground(new java.awt.Color(102, 255, 255));
45 |
46 | jLabel1.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
47 | jLabel1.setText("M Kumarasamy college of engineering");
48 |
49 | javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
50 | jPanel1.setLayout(jPanel1Layout);
51 | jPanel1Layout.setHorizontalGroup(
52 | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
53 | .addGroup(jPanel1Layout.createSequentialGroup()
54 | .addGap(124, 124, 124)
55 | .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
56 | .addGap(152, 152, 152))
57 | );
58 | jPanel1Layout.setVerticalGroup(
59 | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
60 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
61 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
62 | .addComponent(jLabel1)
63 | .addGap(280, 280, 280))
64 | );
65 |
66 | jPanel2.setBackground(new java.awt.Color(153, 204, 255));
67 |
68 | table_dep.setModel(new javax.swing.table.DefaultTableModel(
69 | new Object [][] {
70 | {null, null},
71 | {null, null},
72 | {null, null},
73 | {null, null}
74 | },
75 | new String [] {
76 | "dep_code", "dep_name"
77 | }
78 | ));
79 | jScrollPane1.setViewportView(table_dep);
80 |
81 | javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
82 | jPanel2.setLayout(jPanel2Layout);
83 | jPanel2Layout.setHorizontalGroup(
84 | jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
85 | .addComponent(jScrollPane1)
86 | );
87 | jPanel2Layout.setVerticalGroup(
88 | jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
89 | .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE)
90 | );
91 |
92 | jPanel3.setBackground(new java.awt.Color(204, 204, 255));
93 |
94 | list_dep.setText("List all");
95 | list_dep.addActionListener(new java.awt.event.ActionListener() {
96 | public void actionPerformed(java.awt.event.ActionEvent evt) {
97 | list_depActionPerformed(evt);
98 | }
99 | });
100 |
101 | javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
102 | jPanel3.setLayout(jPanel3Layout);
103 | jPanel3Layout.setHorizontalGroup(
104 | jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
105 | .addGroup(jPanel3Layout.createSequentialGroup()
106 | .addGap(20, 20, 20)
107 | .addComponent(list_dep)
108 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
109 | );
110 | jPanel3Layout.setVerticalGroup(
111 | jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
112 | .addGroup(jPanel3Layout.createSequentialGroup()
113 | .addGap(107, 107, 107)
114 | .addComponent(list_dep)
115 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
116 | );
117 |
118 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
119 | getContentPane().setLayout(layout);
120 | layout.setHorizontalGroup(
121 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
122 | .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
123 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
124 | .addContainerGap()
125 | .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
126 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
127 | .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
128 | );
129 | layout.setVerticalGroup(
130 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
131 | .addGroup(layout.createSequentialGroup()
132 | .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
133 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
134 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
135 | .addGroup(layout.createSequentialGroup()
136 | .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
137 | .addGap(0, 0, Short.MAX_VALUE))
138 | .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
139 | .addContainerGap())
140 | );
141 |
142 | pack();
143 | }// //GEN-END:initComponents
144 |
145 | private void list_depActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_list_depActionPerformed
146 | // TODO add your handling code here:
147 | DefaultTableModel model = (DefaultTableModel) table_dep.getModel();
148 | // DefaultTableModel model = {DefaultTableModel} table_dep.getModel();
149 | while (model.getRowCount()>0){
150 | for(int i=0;i
186 | /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
187 | * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
188 | */
189 | try {
190 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
191 | if ("Nimbus".equals(info.getName())) {
192 | javax.swing.UIManager.setLookAndFeel(info.getClassName());
193 | break;
194 | }
195 | }
196 | } catch (ClassNotFoundException ex) {
197 | java.util.logging.Logger.getLogger(Department.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
198 | } catch (InstantiationException ex) {
199 | java.util.logging.Logger.getLogger(Department.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
200 | } catch (IllegalAccessException ex) {
201 | java.util.logging.Logger.getLogger(Department.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
202 | } catch (javax.swing.UnsupportedLookAndFeelException ex) {
203 | java.util.logging.Logger.getLogger(Department.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
204 | }
205 | //
206 | //
207 |
208 | /* Create and display the form */
209 | java.awt.EventQueue.invokeLater(new Runnable() {
210 | public void run() {
211 | new Department().setVisible(true);
212 | }
213 | });
214 | }
215 |
216 | // Variables declaration - do not modify//GEN-BEGIN:variables
217 | private javax.swing.JLabel jLabel1;
218 | private javax.swing.JPanel jPanel1;
219 | private javax.swing.JPanel jPanel2;
220 | private javax.swing.JPanel jPanel3;
221 | private javax.swing.JScrollPane jScrollPane1;
222 | private javax.swing.JButton list_dep;
223 | private javax.swing.JTable table_dep;
224 | // End of variables declaration//GEN-END:variables
225 | }
226 |
--------------------------------------------------------------------------------
/JAVA/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 balak
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 |
--------------------------------------------------------------------------------
/JAVA/ResultSet.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 balak
10 | */
11 | class ResultSet {
12 |
13 | boolean next() {
14 | throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
15 | }
16 |
17 | String getInt(int i) {
18 | throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
19 | }
20 |
21 | String getString(int i) {
22 | throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------