Breaking News
Loading...
Monday, 15 February 2016

EmployeeManagement full with database connection (s5)

08:03:00
MainForm.java

 -----------------EmployeeForm------------------
 {                                        
       EmployeeForm obj=new EmployeeForm();
       obj.setVisible(true);
        // TODO add your handling code here:
    }                                       
 ------------------------customerForm----------------------
 {                                        
      Customer obj=new Customer();
      obj.setVisible(true);
        // TODO add your handling code here:
    }
----------ProductForm-----------------
 {                                        
       Product obj=new Product();
       obj.setVisible(true);
        // TODO add your handling code here:
    }      
-----------------supplierForm-----------

 {                                       
        Supplier obj=new Supplier();
        obj.setVisible(true);
        // TODO add your handling code here:
    }    
EmployeeForm.java

      ---------------button insert------------------------
 {                                      
         String code=txtcode.getText();
         txtcode.setText("");
         String EmpName=txtempname.getText();
         txtempname.setText("");
         String CellNum=txtCellNum.getText();
         txtCellNum.setText("");
         String empAdd=txtAdrs.getText();
         txtAdrs.setText("");
         String fname=txtfname.getText();
         txtfname.setText("");
         String mail=txtmail.getText();
         txtmail.setText("");
         String dobirth=txtdob.getText();
         txtdob.setText("");
         String bloodgroup=txtbg.getText();
         txtbg.setText("");
         String salery=txtsalery.getText();
         txtsalery.setText("");
         String query="Insert into Employee Values('"+code+"','"+EmpName+"','"+CellNum+"','"+empAdd+"','"+fname+"','"+mail+"','"+dobirth+"','"+bloodgroup+"','"+salery+"')";
             obj.UDI(query);
       
    }                                     
        ------------------button search----------------
 {                                        
       String code=txtcode.getText();
        txtcode.setText("");
      String query="Select * from Employee where Empcode='"+code+"'";
  try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection conn = DriverManager.getConnection(DbConn.path);
            Statement stmt = conn.createStatement();
            stmt.execute(query);
             ResultSet rs = stmt.getResultSet();
             if (rs.next())
             {
                    JOptionPane.showMessageDialog(null,"Search SUCCESSFULLY");
                       txtcode.setText(rs.getString("EmpCode"));
                       txtempname.setText(rs.getString("EmplName"));
                       txtCellNum.setText(rs.getString("EmplCell"));
                       txtAdrs.setText(rs.getString("empAdd"));
                       txtfname.setText(rs.getString("empfname"));
                       txtmail.setText(rs.getString("empmail"));
                       txtdob.setText(rs.getString("empdob"));
                       txtbg.setText(rs.getString("empbd"));
                       txtsalery.setText(rs.getString("empslry"));
             }
            else{
            JOptionPane.showMessageDialog(null,"Record Not Found");
          
               }
            conn.close();
            JOptionPane.showMessageDialog(null,"Search SUCCESSFULLY");
        }
        catch(java.lang.ClassNotFoundException ex)
        {
             JOptionPane.showMessageDialog(null,"Exception Occured"+ex.getMessage());
        }
        catch(Exception ex)
        {
             JOptionPane.showMessageDialog(null,"Exception Occured"+ex.getMessage());
        }   
    ----------button update-------------------                                       
            String code=txtcode.getText();
            txtcode.setText("");
            String EmpName=txtempname.getText();
            txtempname.setText("");
            String CellNum=txtCellNum.getText();
            txtCellNum.setText("");
            String empAdd=txtAdrs.getText();
            txtAdrs.setText("");
            String fname=txtfname.getText();
            txtfname.setText("");
            String mail=txtmail.getText();
            txtmail.setText("");
            String dobirth=txtdob.getText();
            txtdob.setText("");
            String bloodgroup=txtbg.getText();
            txtbg.setText("");
            String salery=txtsalery.getText();
            txtsalery.setText("");
            String query="Update Employee set emplname='"+EmpName+"',emplCell='"+CellNum+"',empAdd='"+empAdd+"',empfname='"+fname+"',empmail='"+mail+"',empdob='"+dobirth+"',empbd='"+bloodgroup+"',empslry='"+salery+"' where EmpCode='"+code+"'";
   obj.UDI(query);
        // TODO add your handling code here:
    }                                      
------------ button delete----------------
 {                                   
 String code=txtcode.getText();
        txtcode.setText("");
         String query="Delete from Employee where Empcode='"+code+"'";
obj.UDI(query);
     // TODO add your handling code here:
    }                                  





                                        Dbconn.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.JOptionPane;


public class DbConn {
    public static String path= "jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb, *.accdb)};DBQ=E:\\EmployeeManagment\\ofcrecord.accdb";
    public DbConn(){
       
    }
    public void UDI(String query){
      try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection conn = DriverManager.getConnection(DbConn.path);
            Statement stmt = conn.createStatement();
            stmt.execute(query);
            conn.close();
            JOptionPane.showMessageDialog(null,"INSERTED SUCCESSFULLY");
        }
        catch(java.lang.ClassNotFoundException ex)
        {
             JOptionPane.showMessageDialog(null,"Exception Occured"+ex.getMessage());
        }
        catch(Exception ex)
        {
             JOptionPane.showMessageDialog(null,"Exception Occured"+ex.getMessage());
        }   
    }
}




       


0 comments:

Post a Comment

 
Toggle Footer