Showing posts with label employees contact list system in java jdbc and oracle database. Show all posts
Showing posts with label employees contact list system in java jdbc and oracle database. Show all posts

Friday, June 15, 2018

Employee's Contact List System in Java JDBC and Oracle Database

Hi there in this article I would like to share with you a sample program that I wrote using Java JDBC and Oracle database to manage the contacts of the employees in the company. I called this program Employee's Contact List System in Java JDBC and Oracle Database. It demonstrates the concept of all basic database operations CRUD (Create, Retrieve, Update and Delete). It allows the user to add, update, delete, view all the records and single employee's record and quite the program. I hope you will find my work useful.

I am currently accepting programming work, it project, school 

programming projects , thesis and capstone projects, IT consulting 

work and web development work kindly contact me in the following email address for further details.  If you want to advertise in my website kindly contact me also in my email address also. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.






Sample Program Output

Program Listing

CRUD.java


package oraclecon;

/**
 *
 * @author Mr. Jake R. Pomperada, MAED-IT
 * Date : June 14, 2018  Thursday
 * Home Address: #25-31 Victoria Malaga Street, Eroreco Subdivision, 
 *               Barangay Mandalagan, 6100 Bacolod City, Negros Occidental
 * Email Address : jakerpomperada@yahoo.com and jakerpomperada@gmail.com
 */
import java.sql.*;
import java.io.*;

public class CRUD {

    Connection con;
    PreparedStatement ps;

    public CRUD() {
        try {
             Class.forName("oracle.jdbc.driver.OracleDriver");
             con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "hr");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
                
    
    public void insertEmp(int id, String lastname, String firstname, String address, String email, String mobile) {
        try {
            ps = con.prepareStatement("INSERT INTO HR.EMP values(?,?,?,?,?,?)");
            ps.setInt(1, id);
            ps.setString(2, lastname);
            ps.setString(3, firstname);
            ps.setString(4, address);
            ps.setString(5, email);
            ps.setString(6, mobile);
            int i = ps.executeUpdate();
            if (i != 0) {
                System.out.println("Record is successfully inserted in the database.");
                System.out.println();
            } else {
                System.out.println("Record is not successfully inserted in the database.");
                System.out.println();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void updateEmp(int id, String lastname, String firstname, String address, String email, String mobile) {
        try {
            ps = con.prepareStatement("UPDATE HR.EMP SET lastname=?,firstname=?,address=?,email=?,mobile=? WHERE id=?");
            ps.setString(1, lastname);
            ps.setString(2, firstname);
            ps.setString(3, address);
            ps.setString(4, email);
            ps.setString(5, mobile);
            ps.setInt(6, id);
            int i = ps.executeUpdate();
            if (i != 0) {
                System.out.println("Record is succesffuly updated.");
                System.out.println();
            } else {
                System.out.println("Record is not updated.");
                System.out.println();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void deleteEmp(int id) {
        try {
            ps = con.prepareStatement("DELETE FROM HR.emp WHERE id=?");
            ps.setInt(1, id);
            int i = ps.executeUpdate();
            if (i != 0) {
                System.out.println("Record is succesfully deleted.");
                System.out.println();
            } else {
                System.out.println("Record is not deleted.");
                System.out.println();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void dispAll() {
        try {
            Statement st = con.createStatement();
            ResultSet res = st.executeQuery("SELECT * FROM HR.EMP");
            while (res.next()) {
                System.out.println("ID Number       : " + res.getString(1));
                System.out.println("Last Name       :  " + res.getString(2));
                System.out.println("First Name      :   " + res.getString(3));
                System.out.println("Home Address    : " + res.getString(4));
                System.out.println("Email Address   : " + res.getString(5));
                System.out.println("Mobile Number   :  " + res.getString(6));
                System.out.println();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void dispAnEmp(int s) {
        try {
            ps = con.prepareStatement("SELECT * FROM HR.EMP WHERE id=?");
            ps.setInt(1, s);
            ResultSet res = ps.executeQuery();
            if (res.next()) {
                System.out.println("ID Number       : " + res.getString(1));
                System.out.println("Last Name       :  " + res.getString(2));
                System.out.println("First Name      :   " + res.getString(3));
                System.out.println("Home Address    : " + res.getString(4));
                System.out.println("Email Address   : " + res.getString(5));
                System.out.println("Mobile Number   :  " + res.getString(6));
                System.out.println();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        try {
            CRUD obj = new CRUD();
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int ch = 0;
            while (true) {
                System.out.println("\tEMPLOYEE'S CONTACT LIST SYSTEM IN JAVA JDBC AND ORACLE DATABASE\n\n"
                        + "\t\t CREATED BY MR. JAKE RODRIGUEZ POMPERADA,MAED-IT \n\n"
                        + "\t 1. ADD EMPLOYEE'S RECORD \n "
                        + "\t 2. UPDATE EMPLOYEE'S RECORD \n "
                        + "\t 3. DELETE EMPLOYEE'S RECORD \n "
                        + "\t 4. DISPLAY ALL EMPLOYEE'S RECORD \n "
                        + "\t 5. DISPLAY A SINGLE EMPLOYEE'S RECORD \n"
                        + "\t 6. QUIT PROGRAM \n\n"
                        + "\t SELECT YOUR OPTION :  \n");
                String str1 = br.readLine().toString();
                ch = Integer.parseInt(str1);
                switch (ch) {
                    case 1: {
                        System.out.println("Employee Code ");
                        String code = br.readLine();
                        int id = Integer.parseInt(code);
                        System.out.println("Last Name" );
                        String lastname = br.readLine();
                        System.out.println("First Name ");
                        String firstname = br.readLine();
                        System.out.println("Address ");
                        String address = br.readLine();
                        System.out.println("Email ");
                        String email = br.readLine();
                        System.out.println("Mobile ");
                        String mobile = br.readLine();
                        obj.insertEmp(id,lastname,firstname,address,email,mobile);
                        break;
                    }
                    case 2: {
                        System.out.println("Employee Code ");
                        String code = br.readLine();
                        int id = Integer.parseInt(code);
                        System.out.println("Last Name" );
                        String lastname = br.readLine();
                        System.out.println("First Name ");
                        String firstname = br.readLine();
                        System.out.println("Address ");
                        String address = br.readLine();
                        System.out.println("Email ");
                        String email = br.readLine();
                        System.out.println("Mobile ");
                        String mobile = br.readLine();
                        obj.updateEmp(id,lastname,firstname,address,email,mobile);
                        break;
                    }
                    case 3: {
                        System.out.print("Enter Employee Code to delete record : ");
                        String code = br.readLine();
                         int id = Integer.parseInt(code);
                        obj.deleteEmp(id);
                        break;
                    }
                    case 4: {
                        obj.dispAll();
                        break;
                    }
                    case 5: {
                        System.out.print("Enter Employee Code to display record : ");
                        String code = br.readLine();
                        int id = Integer.parseInt(code);
                        obj.dispAnEmp(id);
                        break;
                    }
                    case 6:
                    {
                        System.exit(0);
                    }
                    default:
                        break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}  // End of Code