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();
  }
    
}    


    




No comments:

Post a Comment