Friday, June 15, 2018

Login System in Java JDBC and Oracle 11g Database

In this article I would like to share with you guys a Login System that I revised using Java JDBC and by this time our database is Oracle 11g. The code is very short and easy to understand what is important in running this code the library file ojdbc6.jar must also resides in your working directory in order to run the code properly. The ojdbc6.jar is a library file which connects your Java code in your Oracle 11g database. 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

Login.java

import java.io.Console;
import java.sql.*;


public class Login {
    
static Connection conn;

   static void closeConnection() {
        try {
            
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

void display() {
        Console console = System.console(); 
    console.printf("\n");
    console.printf("===== LOGIN SYSTEM IN JAVA JDBC AND ORACLE DATABASE =====");
    console.printf("\n\n");
        console.printf("Enter Username : ");
        String userName = console.readLine();
        char passwordArray[] = console.readPassword("Enter Password: ");
        String passWord = new String(passwordArray);
    
            String selectSQL = "select * from hr.users where username = ? and password = ?";
 
          try {

              
             conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "hr");
     
            PreparedStatement ps = conn.prepareStatement(selectSQL);
            ps.setString(1, userName);
            ps.setString(2, passWord);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
  String lastname = rs.getString(5);
                           String firstname = rs.getString(4);
              System.out.println("\n");
  System.out.println("Welcome to the System Mr/Ms. " 
                                  + firstname.toUpperCase() 
                                  + " " + lastname.toUpperCase() + ".");
  System.out.println("\n");   
}
else
{
    System.out.println("\n");
            System.out.println("Intruder Detected. Please Call the System Administrator.");
System.out.println("\n");
display();
}
       
       closeConnection();
             
              
        }  catch (SQLException ex) {
            ex.printStackTrace();
            
    }

}
public static void main(String[ ] args) {
               
      Login  Start = new Login();
      Start.display();
  }
    
}    


    




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







Sunday, June 10, 2018

Insert Record in Java JDBC and Oracle 11g Database

In this article I would like to share with you how to insert or add a record using Java JDBC and Oracle 11g database express edition that code is very simple and easy to understand.

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

InsertRecord.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package oraclecon;

import java.sql.*;

/**
 *
 * @author Jake Pomperada
 */
public class InsertRecord {
    public static void main(String args[])
    {
        int Id = 6;
        String Name = "JULIANNA";
        int Age=4;
        String Address ="BACOLOD";
         
        try
        {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "hr");
            Statement stmt = con.createStatement();
             
            // Inserting data in database
            String q1 = "INSERT INTO hr.customers VALUES('" +Id+ "', '" +Name+ 
                                  "', '" +Age+ "', '" +Address+ "')";
            int x = stmt.executeUpdate(q1);
            if (x > 0)            
                System.out.println("Successfully Inserted");            
            else           
                System.out.println("Insert Failed");
             
            con.close();
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
}


Customer Listing System Using Java JDBC and Oracle Database

In this article I would like to share with you guys a program that I wrote using Java JDBC and Oracle 11g Express Edition to display the customer records from the Oracle Database. This will be my first time to use Oracle as my database to store records of the customer. I find it very challenging at first but it is very worth while in learning new database like Oracle. I hope you find it useful my sample program.  

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

Oraclecon.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


package oraclecon;


import java.sql.*;  
import java.sql.DriverManager;
import java.sql.Connection;

/**
 *
 * @author Jake R. Pomperada
 * June 10, 2018
 * Sunday, Bacolod City, Negros Occidental
 */
public class OracleCon {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       try{  
//step1 load the driver class  
Class.forName("oracle.jdbc.driver.OracleDriver");  
  
//step2 create  the connection object  
Connection con=DriverManager.getConnection(  
"jdbc:oracle:thin:@localhost:1521:xe","system","hr");  
  
//step3 create the statement object  
Statement stmt=con.createStatement();  
  
//step4 execute query  

System.out.println("CUSTOMER LISTING SYSTEM USING JAVA JDBC AND ORACLE DATABASE");
System.out.println();
System.out.println("Created By Mr. Jake R. Pomperada,MAED-IT");
System.out.println();

ResultSet rs=stmt.executeQuery("SELECT * FROM HR.CUSTOMERS ORDER BY ID ASC ");  
while(rs.next())  {
System.out.println("ID       :    "  +  rs.getInt(1));
System.out.println("Name     :    "  +  rs.getString(2));
System.out.println("Age      :    "  +  rs.getString(3));
System.out.println("Address  :    "  +  rs.getString(4));  
System.out.println(); 

  
}
System.out.println();
System.out.println("===== End of Program =====");
System.out.println(); 
//step5 close the connection object 
con.close();
}catch(Exception e){ System.out.println(e);}  
  
    }
    
}