Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

House Rental System

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Project Title: House Rental System

Usage:
● Programming Language: Java
● Application Programming Interface (API): RMI (Remote Method Invocation)

Functionality:
The House Rental System is designed to facilitate the process of renting houses. It
provides the following functionalities:

Preparation:
Before using the functionalities of the House Rental System, ensure to start the
necessary servers in the following sequence: Home Server, Rent Server, and Notice
Server. Once the servers are running, proceed with utilizing the system functionalities.

RMI Implementation:

The RMI implementation for the Home module consists of the following components:

1. Home Server:

Home:
The Home functionality focuses on user authentication, including login and signup
processes.

public static void main(String[] args) {


try {
HomeServer obj = new HomeServer();

Registry Registry = LocateRegistry.createRegistry(3001);


Registry.rebind("home", obj);
System.out.println("Server Ready...");
} catch (Exception e) {
e.printStackTrace();
}}

@Override
public boolean login(String username, String Password) throws RemoteException {

String sql= "select * from user where Username=? and Password=?";


try{
pst=conn.prepareStatement(sql);
pst.setString(1, username);
pst.setString(2, Password);
rs = pst.executeQuery();
if(rs.next()){
rs.close();
pst.close();
return true;
}else{
return false;
}
}catch(Exception e){
return false;
}

@Override
public boolean signUp(String Name, String Username, String Sec_Q, String Answer, String Password)
throws RemoteException {
System.out.println("homeee :::" );
try {
String sql = "INSERT INTO `user`(`Name`, `Username`, `Sec_Q`, `Answer`, `Password`) VALUES
(?,?,?,?,?)";
pst = conn.prepareStatement(sql);
pst.setString(1, Name);
pst.setString(2, Username);
pst.setString(3,Sec_Q);
pst.setString(4, Answer);
pst.setString(5, Password);
pst.execute();
// rs.close();
// pst.close();

return true;
} catch (Exception e) {
System.out.println("e.printStackTrace(); :::" + e.getMessage());
return false;
}
}

Home service :-

The home service interface will contain the defined methods for login and
signup.

public interface HomeService extends Remote {


public boolean login(String username, String Password) throws RemoteException;

public boolean signUp(String Name, String Username, String Sec_Q, String Answer, String Password)
throws RemoteException;
}

The HomeServer class implements the HomeService interface, providing


implementations for the login and signUp methods. These methods handle user
authentication and registration functionalities respectively.

The HomeService interface defines the methods login and signUp, which are
accessible remotely via RMI.

This setup allows clients to securely interact with the House Rental System, performing
authentication and registration tasks seamlessly.

2. Rent:
The Rent functionality manages the rental operations for houses. It includes adding
rental records and managing house rentals.

RMI Implementation:

The RMI implementation for the Rent module consists of the following components:

Rent Server:

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class RentServer extends UnicastRemoteObject implements RentService {

Connection conn;
PreparedStatement pst;
ResultSet rs;

public RentServer() throws RemoteException {


conn = DbConnect.ConnecrDb();
}

@Override
public boolean rent(String day, String month, String year, String houseNo, String floor, String unit,
String rent, String electric, String gasBill, String waterBill, String otherCharges, String total, String status)
throws RemoteException {
try {
String sql = "INSERT INTO `rent`(`Day`, `Month`, `Year`, `House_No`, `Floor`, `Unit`, `Rent`,
`Electricity_Bill`, `Gas_Bill`, `Water_bill`, `Other_Charges`, `Total`, `Status`) VALUES
(?,?,?,?,?,?,?,?,?,?,?,?,?)";
pst = conn.prepareStatement(sql);
pst.setString(1, day);
pst.setString(2, month);
pst.setString(3, year);
pst.setString(4, houseNo);
pst.setString(5, floor);
pst.setString(6, unit);
pst.setString(7, rent);
pst.setString(8, electric);
pst.setString(9, gasBill);
pst.setString(10, waterBill);
pst.setString(11, otherCharges);
pst.setString(12, total);
pst.setString(13, status);
pst.execute();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
} finally {
try {
if (pst != null) {
pst.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}

@Override
public boolean houseRent(String houseNo, String floor, String unit, String tenantName, String contact,
String nId, String familyMember, String date) throws RemoteException {
try {
String sql = "INSERT INTO `houserent`(`House_No`, `Floor`, `Unit`, `Contact`, `N_Id`,
`Family_Member`, `Date`) VALUES (?,?,?,?,?,?,?)";
pst = conn.prepareStatement(sql);
pst.setString(1, houseNo);
pst.setString(2, floor);
pst.setString(3, unit);
pst.setString(4, contact);
pst.setString(5, nId);
pst.setString(6, familyMember);
pst.setString(7, date);
pst.execute();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
} finally {
try {
if (pst != null) {
pst.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
try {
RentServer obj = new RentServer();

Registry registry = LocateRegistry.createRegistry(3002);


registry.rebind("rent", obj);
System.out.println("Rent Server Ready...");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Rent Service

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface RentService extends Remote {


public boolean rent(String day, String month, String year, String houseNo, String floor, String unit,
String rent, String electric, String gasBill, String waterBill, String otherCharges, String total, String status)
throws RemoteException;

public boolean houseRent(String houseNo, String floor, String unit, String tenantName, String contact,
String nId, String familyMember, String date) throws RemoteException;
}

In the RentServer class, methods like rent and houseRent are implemented, which
respectively handle the addition of rent records and house rentals to the database.
These methods are accessible remotely via RMI.

The RentService interface defines the methods rent and houseRent, which are
accessible to clients for performing rental operations remotely.
This setup enables users to manage rental activities within the House Rental System
seamlessly, providing efficient rental record management and house rental
functionalities.

3. Notice:
The Notice functionality handles the management of notices related to houses. It
includes adding new notices and deleting existing notices.

RMI Implementation:

The RMI implementation for the Notice module consists of the following components:

Notice Server:

public class NoticeServer extends UnicastRemoteObject implements NoticeService {

Connection conn;
PreparedStatement pst;
ResultSet rs;

public NoticeServer() throws RemoteException {


conn = DbConnect.ConnecrDb();
}

public static void main(String[] args) {


try {
NoticeServer obj = new NoticeServer();

Registry registry = LocateRegistry.createRegistry(3004);


registry.rebind("notice", obj);
System.out.println("Notice Server Ready...");
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public boolean addNotice(String houseNo, String floor, String unit, String status, String date) throws
RemoteException {
try {
String sql = "INSERT INTO `Notice`(`House_No`, `Floor`, `Unit`, `Status`, `Date`) VALUES
(?,?,?,?,?)";
pst = conn.prepareStatement(sql);
pst.setString(1, houseNo);
pst.setString(2, floor);
pst.setString(3, unit);
pst.setString(4, status);
pst.setString(5, date);
pst.execute();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
} finally {
try {
if (pst != null) {
pst.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}

@Override
public boolean deleteNotice(String serial) throws RemoteException {
try {
String sql = "DELETE FROM `Notice` WHERE Serial=?";
pst = conn.prepareStatement(sql);
pst.setString(1, serial);
pst.execute();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
} finally {
try {
if (pst != null) {
pst.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
Notice Service:

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface NoticeService extends Remote {


public boolean addNotice(String houseNo, String floor, String unit, String status, String date)
throws RemoteException;

public boolean deleteNotice(String serial) throws RemoteException;


}

In the NoticeServer class, methods like addNotice and deleteNotice are


implemented, which respectively handle the addition and deletion of notices in the
database. These methods are accessible remotely via RMI.

The NoticeService interface defines the methods addNotice and deleteNotice,


which are accessible to clients for managing notices remotely.

This setup enables users to efficiently add and delete notices related to houses within
the House Rental System.

Database Connection:
The House Rental System utilizes a MySQL database to store information related to
houses, rentals, users, and notices. The database connection is established using the
following setup:

DbConnect Class:

public class DbConnect {

Connection conn;
public static Connection ConnecrDb() {

try {

// Establishing a connection to the MySQL database

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/hrms", "admin",


"admin@123");

return conn;

} catch (Exception e) {

// Handle any exceptions that occur during the connection process

System.out.println("Error connecting to the database: " + e.getMessage());

return null;

The DbConnect class contains a static method ConnecrDb responsible for creating a
connection to the MySQL database. It uses the JDBC driver to connect to the database
server running locally on port 3306 with the database name hrms. The connection is
established with the username admin and the corresponding password.

This method returns a Connection object representing the established database


connection. In case of any errors during the connection process, appropriate error
handling is implemented to display error messages.

By encapsulating the database connection logic within the DbConnect class, the House
Rental System ensures a centralized and organized approach to managing the database
connections throughout the application.
This setup allows the system to seamlessly interact with the MySQL database,
facilitating efficient storage and retrieval of information related to house rentals and
notices.

Summary:
The House Rental System provides a comprehensive solution for managing house
rentals, user authentication, and notice management. Leveraging the RMI technology, it
offers secure and efficient communication between clients and servers. The system's
modular architecture ensures flexibility and scalability, allowing for easy extension and
integration of additional functionalities. With its MySQL database backend, the system
ensures reliable storage and retrieval of data, enabling seamless operation and
management of house rental activities.

You might also like