0% found this document useful (0 votes)
131 views

Airline Reservation System

This document contains code for an airline reservation system using Java RMI (Remote Method Invocation). It defines an interface for booking seats that is implemented by the AirlineServer class. The AirlineClient class acts as a client that looks up the remote object and calls the bookSeat method, displaying the results. The server maintains seat availability in a database and returns the number of available seats or a message if none are available.

Uploaded by

SANGEETHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views

Airline Reservation System

This document contains code for an airline reservation system using Java RMI (Remote Method Invocation). It defines an interface for booking seats that is implemented by the AirlineServer class. The AirlineClient class acts as a client that looks up the remote object and calls the bookSeat method, displaying the results. The server maintains seat availability in a database and returns the number of available seats or a message if none are available.

Uploaded by

SANGEETHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

AIRLINEINTERFACE

import java.rmi.*;

public interface AirlineInterface extends Remote

public int bookSeat(String FlightNo) throws RemoteException;

AIRLINESERVER

import java.rmi.*;

import java.rmi.server.*;

import java.rmi.registry.*;

import java.util.*;

import java.sql.*;

public class AirlineServer extends UnicastRemoteObject implements AirlineInterface

String url = "jdbc:odbc:airline";

Connection conn;

// Server Constructor

public AirlineServer( ) throws RemoteException

System.out.println("Initializing the Server");

}
// The bookSeat() method.

public int bookSeat(String FlightNo)

int seatdtls=0;

System.out.println("Flight is " + FlightNo);

try

// Load the Driver

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

// Pass the static fields containing the data source name

conn = DriverManager.getConnection(url);

Statement stmt = conn.createStatement();

ResultSet rs= stmt.executeQuery("Select Seats from Flight where Flightno = '"


+FlightNo+ "'");

while (rs.next())

seatdtls = rs.getInt("Seats");

catch(Exception excp) {}
if (seatdtls > 0 )

return seatdtls;

else

return 0;

} //End of bookSeat() method

// Implement the main() method

public static void main(String args[])

try

// create an instance of the Server object to export

AirlineServer arlnServer = new AirlineServer();

Naming.rebind("airlineServ", arlnServer);

/* airlineServ is the name under which the server registers itself in the RMI
registry. */

System.out.println("Server Ready");

} // End of try block

catch (RemoteException RemotExcp)

System.out.println("Remote Server Error: " + RemotExcp.getMessage());

System.exit(0);

}
catch (Exception excp)

System.out.println("Error: " + excp.getMessage());

System.exit(0);

} // End of main() method

} // End of Server class

AIRLINECLIENT

import java.rmi.*;

import java.rmi.registry.*;

import java.awt.*;

import java.awt.event.*;

public class AirlineClient extends Frame implements ActionListener

Button btnBookSeat = new Button("Seat Availability");

// Create Labels

Label lblFlightNo = new Label("Flight No:");

Label lblResults = new Label("Results:");


// Create a text area

TextArea taResults = new TextArea();

// Create Text Items

TextField txtFlightNo = new TextField(20);

// Constructor of the AirlineClient

public AirlineClient()

super("Airline Reservation System (Remote Client - RMI)");

setLayout (null);

lblFlightNo.setBounds(20,50,55,25);

add(lblFlightNo);

txtFlightNo.setBounds(150,50,100,25);

add(txtFlightNo);

lblResults.setBounds(20,155,100,25);

add(lblResults);

taResults.setBounds(150,155,400,200);

add(taResults);

btnBookSeat.setBounds(175,375,250,25);
add(btnBookSeat);

// Add listeners for the buttons

btnBookSeat.addActionListener(this);

enableEvents(AWTEvent.WINDOW_EVENT_MASK);

} // End of the remote class constructor AirlineClient()

public void processWindowEvent(WindowEvent winEvt)

if(winEvt.getID() == WindowEvent.WINDOW_CLOSING)

setVisible(false);

dispose();

System.exit(0);

// To trap events for each buttons

public void actionPerformed(ActionEvent actEvt)

if (actEvt.getSource() == btnBookSeat)

{
seatcheck();

} // End of actionPerformed() method

public void seatcheck()

String Flight=txtFlightNo.getText();

int val;

try

String ServerURL = "//127.0.0.1/airlineServ";

AirlineInterface alIntf = (AirlineInterface)Naming.lookup(ServerURL);

val = alIntf.bookSeat(Flight);

if (val == 0)

taResults.setText("No seats available for flight " + Flight);

else

taResults.setText("The seats available on flight " + Flight + " are " + val);

}
catch(Exception excp)

System.out.println("Exception: "+excp);

// AirlineClient main() method

public static void main(String [] args)

// Invoke the constructor of the AirlineClient class

AirlineClient rmtAirline = new AirlineClient();

rmtAirline.setVisible(true);

rmtAirline.setSize(600,500);

} // End of main() method

} // End of AirlineClient class

You might also like