0% found this document useful (0 votes)
49 views4 pages

Rmi - Stock Market

1. The document describes a Java program that uses RMI to lookup stock values from a Microsoft Access database table. 2. It creates a table with company names and stock values, then implements a StockImpl class to retrieve values by name. 3. A client enters a company name, which is looked up via RMI and the stock value returned, demonstrating successful use of RMI to query the database.

Uploaded by

prasath
Copyright
© Attribution Non-Commercial (BY-NC)
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)
49 views4 pages

Rmi - Stock Market

1. The document describes a Java program that uses RMI to lookup stock values from a Microsoft Access database table. 2. It creates a table with company names and stock values, then implements a StockImpl class to retrieve values by name. 3. A client enters a company name, which is looked up via RMI and the stock value returned, demonstrating successful use of RMI to query the database.

Uploaded by

prasath
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 4

RMI – STOCK MARKET

Aim: To write a java program to use the RMI concept to get stock value of shares of
companies that exits in the databases in an MSAccess table.

Algorithm:

Table creation and connection establishment:


1. Open MS-Access from program and create a table with the fields like company name,
stock value and save the table in the name of stock.
2. Give some values in the table with the company names and their corresponding share
values.
3. Now save the values and go to RUN and give obbead32 and choose the drive in which
your table resides and add the MS-Access Driver file.
4. Now give the drive source name as mysource and click on start then select the stock table
that was created and click ok.

Implementation:
1. In the implementation file we receive the input of the company’s name given by the user.
2. We set the path to the address where the mysource drive is present.
3. We create objects for the Connection and Statement classes and we execute the Query
and select all the fields in the table.
4. Now we check each company’s name with the input given, If it matches we return the
value of that particular companies share.
Server:
1. In the server side we jus create an object for the StockImpl and we bind it with the
implementer.
2. We then just print a message saying that the object has been registered.
3. If any exception occurs we catch it and just print it.

Client:
1. In the client side we first get the input from the user using the readLine() of the
DataInputStream class through our I/O.
2. After getting the input we pass it to the implementer and we lookup in the table for this
company’s name.
3. If the name is present in the table the client prints the company’s name along with its
stock value.
4. If any exception occurs we catch it and just print it.
Program:

Module:

import java.rmi.*;
interface stockWatch extends Remote
{
public int get_stockValue(String name) throws Exception;
}

Implementation:

import java.rmi.*;
import java.rmi.server.*;
import java.sql.*;
import java.io.*;
public class stockImpl extends UnicastRemoteObject implements stockWatch{
int value;
public stockImpl()throws RemoteException{
}
public int get_stockValue(String symbol) throws RemoteException{
try{
System.out.println("The company to be searched up is:"+symbol);
float price=0;

String url="jdbc:odbc:mysource2";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection myConnection=DriverManager.getConnection(url);
Statement myStatement=myConnection.createStatement();
ResultSet rs=myStatement.executeQuery("Select * from stock where
Comp_Name='"+symbol+"'");

while(rs.next())
{
value=rs.getInt(2);
System.out.print(value);
System.out.println();
}
myStatement.close();
myConnection.close();
return value;
}
catch(Exception e)
{
System.out.println("Exception caught"+e);
return 0;
}}}

Server:

import java.rmi.*;
import java.net.*;
import java.io.*;
public class rmiserver
{ public static void main(String args[])
{
try
{
stockImpl stock=new stockImpl();
Naming.bind("stockmarket",stock);
System.out.println("OBJECT IS REGISTERED");
}
catch(Exception e)
{
System.out.println("EXCEPTION :"+e);
}
}}

Client:
import java.io.*;
import java.rmi.*;
import java.net.*;
public class rmiclient
{
public static void main(String args[]) throws Exception
{
try
{
DataInputStream din=new DataInputStream(System.in);
String s1="rmi://localhost/stockmarket";
stockWatch stock=(stockWatch)Naming.lookup(s1);
System.out.println("Enter the company name:");
String name=din.readLine();
System.out.println(name+"'s one stock costs Rs"+stock.get_stockValue(name));
}
catch(Exception e)
{
System.out.println("EXCEPTION :"+e);
}
}
}

OUTPUT:

Server side commands:

C:\CORBA>set path=c:\jdk\bin

C:\CORBA>start rmiregistry

C:\CORBA>javac rmiserver. java

C:\CORBA>java rmiserver

Object is registered.

The company to be searched up is: TCS


1000.0

Client side commands:

C:\CORBA>set path=c:\jdk\bin

C:\CORBA>start rmiregistry

C:\CORBA>javac rmiclient. java

C:\CORBA>java rmiclient
Enter the company Name:
TCS
TCS’s one stock costs 1000.0

Result: Thus the java program to use the RMI concept to get stock value of shares of
companies that exits in the databases in MSAccess table was completed successfully.

You might also like