middleware lab programs
DESCRIPTION
Middleware Lab ProgramsTRANSCRIPT
Ex.No: 1
FILE DOWNLOADING USING RMI
AIM:
To write a java program to download a file using rmi.
HARDWARE SPECIFICATIONS:
1.Mother Board : MSI2. Processor : AMD Athlon (64 bit)3. Hard Disk : 80 GB4. Ram : 640 MB5. Monitor :15’inch HCL6. Keyboard : HCL7. Mouse : HCL Optical Mouse
SOFTWARE SPECIFICATIONS:
1. Microsoft Visual Studio 20082. Net Beans 7.0
ALGORITHM:
Step 1: Start the program.
Step 2: Write the interface code.
Step 3: Write the implementation source for implementing the connection.
Step 4: Write the client and server code to download the file from server.
Step 5: Compile all the java files.
Step 6: Start the rmi registry by c:\jdk1.5\bin>start rmiregistry.
Step 7: Run the server and client in separate window.
Step 8: Stop the program.
1
PROGRAM:
Intr.java:
import java.rmi.RemoteException;
import java.rmi.Remote;
public interface intr extends Remote
{
public byte[ ] loadfile(String filename) throws RemoteException;
}
Impl.java:
import java.io.*;
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
public class impl extends UnicastRemoteObject implements intr
{
public impl (String str)throws RemoteException
{
super();
}
public byte[ ] loadfile(String filename)
{
try
{
File f1=new File(filename);
byte buff[ ]=new byte[(int)f1.length() ];
BufferedInputStream bif=new BufferedInputStream(new
FileInputStream(filename));
bif.read(buff,0,buff.length);
bif.close();
return(buff);
}
catch(Exception e)
2
{
}
return(null);
}
}
Serv.java:
import java.io.*;
import java.rmi.*;
public class serv
{
public static void main(String args[ ])
{
try
{
impl f =new impl("serv");
Naming.rebind("serv",f);
System.out.println("\n\t Service Hosted on sever & Client Connected
Now….");
}
catch(Exception e)
{ }
}
}
Clien.java:
import java.io.*;
import java.rmi.*;
public class clien
{
public static void main(String args[ ])
{
try
{
3
String str="rmi://localhost/serv";
intr f =(intr)Naming.lookup(str);
byte[ ]data=f.loadfile(args[0]);
File fs=new File(args [1]);
BufferedOutputStream bf=new BufferedOutputStream(new
FileOutputStream(fs.getName()));
bf.write(data,0,data.length);
bf.flush();
bf.close();
System.out.println("File has been downloaded");
}
catch(Exception e)
{ }
}
}
4
OUTPUT:
C:\jdk1.5\bin>javac *.java
C:\jdk1.5\bin>start rmiregistry
Server window:
C:\jdk1.5\bin>java serv
You Are Connected
Client window:
C:\jdk1.5\bin>java clien t1.txt t2.txt
File has been downloaded
T2.txt window:
RESULT:
Thus the program has been executed and the download has been done successfully.
5
Ex.No: 2
GRAPHICAL SHAPES USING BDK
AIM:
To write a java bean program to draw various graphical shapes using BDK.
HARDWARE SPECIFICATIONS:
1.Mother Board : MSI2. Processor : AMD Athlon (64 bit)3. Hard Disk : 80 GB4. Ram : 640 MB5. Monitor :15’inch HCL6. Keyboard : HCL7. Mouse : HCL Optical Mouse
SOFTWARE SPECIFICATIONS:
1. Microsoft Visual Studio 20082. Net Beans 7.0
ALGORITHM:
Step 1: Start the program.
Step 2: Create the java bean file Circle.java.
Step 3: Create the mft file Circle.mft.
Step 4: Create a folder in the path C:\j2sdk1.4.2_08\bin\bdk and save all the files.
Step 5: Compile the files using javac *.java.
Step 6: Create the jar file by C:\j2sdk1.4.2_08\bin\bdk>jar cfm Circle.jar
Circle.mft Circle.class.
Step 7: Now open the beanbox from C:\BDK1_1\beans\beanbox and double click
the run command.
Step 8: From the BeanBox opened select LoadJar from file menu.
Step 9: In the dialog box select the jar file that u have created and saved.
Step 10: The jar file will be loaded to the ToolBox named Circle.
Step 11: Now click and drag the ircle to the BeanBox.
Step 12: Stop the program.
6
PROGRAM:
Circle.mft
Name: Circle.class
Java-Bean: True
Circle.java
import java.awt.*;
import java.beans.*;
public class Circle extends Canvas
{
private Color color,bcolor;
public Circle()
{
color=Color.red;
bcolor=Color.blue;
setSize(200,200);
}
public Color getColor()
{
return color;
}
public void setColor(Color c)
{
color=c;
}
public Color getBackgroundColor()
{
return bcolor;
}
public void setBackgroundColor(Color c)
{
bcolor=c;
7
}
public void paint(Graphics g)
{
g.setColor(color);
setBackground(bcolor);
g.fillOval(10,10,30,30);g.fillRect(10,60,40,80);
g.drawLine(60,20,180,20);
g.fillRoundRect(80,150,100,180,20,30);
g.fillArc(120,200,150,200,0,45);
}
}
8
OUTPUT:
C:\j2sdk1.4.2_08\bin\bdk>javac *.java
C:\j2sdk1.4.2_08\bin\bdk>jar cfm Circle.jar Circle.mft Circle.class
C:\j2sdk1.4.2_08\bin\bdk>
BEANBOX:- GRAPHICAL SHAPES
RESULT:
Thus the program has been executed and the drawings were created successfully.
9
Ex.No: 3
BANKING OPERATION USING EJB
AIM:
To write an EJB program to perform the Banking Operations.
HARDWARE SPECIFICATIONS:
1.Mother Board : MSI2. Processor : AMD Athlon (64 bit)3. Hard Disk : 80 GB4. Ram : 640 MB5. Monitor :15’inch HCL6. Keyboard : HCL7. Mouse : HCL Optical Mouse
SOFTWARE SPECIFICATIONS:
1. Microsoft Visual Studio 20082. Net Beans 7.0
ALGORITHM:
Step 1: Start the program.
Step 2: Put all the required .java files in a folder bank.
Step 3: Set the classpath C:\bank>set
CLASSPATH=C:\Sun\AppServer\lib\j2ee.jar.
Step 4: Compile all the .java files C:\bank>javac *.java.
Step 5: Open the J2EE server Deployement Tool.
Step 6: Select new Application from file menu and give the application display
name and click ok.
Step 7: Select newEnterprise bean from the file menu and add the ejb class file
from edit contents.
Step 8: Select newApplication client from the file menu and add the client class
files from the edit contents.
Step 9: Select deploy from the tools menu.
10
Step 10: Open the dos window and enter into bank folder as C:/Bank.
Step 11: Set application path as C:/Bank>set
APPCPATH=c:\bank\bankAPPClient.jar.
Step 12: Set path as C:/Bank>set path=c:\Sun\AppServer\bin;
Step 13: Run the client using C:/Bank>appclient -client bankAPP.ear -name
bankClient –textauth
Step 14: Stop the program.
11
PROGRAM:
BankHome.java
import javax.ejb.EJBHome;
public interface BankHome extends EJBHome
{
public Bank create(int bal) throws java.rmi.RemoteException,
javax.ejb.CreateException;
}
Bank.java
import javax.ejb.EJBObject;
public interface Bank extends EJBObject
{
public int deposit(int amt)throws java.rmi.RemoteException;
public int withdraw(int amt)throws java.rmi.RemoteException;
}
BankBean.java
import java.util.*;
import java.io.*;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public class BankBean implements SessionBean
{
int balance;
private javax.ejb.SessionContext m_ctx=null;
public void setSessionContext(SessionContext ctx)
{
m_ctx=ctx;
}
public void ejbCreate(int bal) throws
java.rmi.RemoteException,javax.ejb.CreateException
{
balance=bal;
12
}
public void ejbRemove()
{}
public void ejbActivate()
{}
public void ejbPassivate()
{}
public int deposit(int amt)
{
balance+=amt;
return(balance);
}
public int withdraw(int amt)
{
balance-=amt;
return(balance);
}
}
BankClient.java
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.io.*;
public class bankClient
{
public static void main(String[] args)
{
Bank myBankRemote=null;
BankHome myBankHome=null;
int amount,balance;
try
{
//The javax.naming.InitialContext class implements the //Context interface
and serves as our entry point to a naming system
13
InitialContext initial = new InitialContext();
String JNDIName="ejb/SimpleBank";
Object obj=initial.lookup(JNDIName);
myBankHome=(BankHome)PortableRemoteObject.narrow(obj,BankHom
e.class);
myBankRemote=myBankHome.create(5000);
DataInputStream in=new DataInputStream(System.in);
while(true)
{
System.out.println("Banking Operations\n1.Deposit\n2.Withdraw\
n3.Exit");
System.out.println("Enter ur choice");
int ch=Integer.parseInt(in.readLine());
switch(ch)
{
case 1://deposit
System.out.println("Enter the deposit amount");
amount=Integer.parseInt(in.readLine());
balance=myBankRemote.deposit(amount);
System.out.println("Total amount is"+balance);
break;
case 2://withdraw
System.out.println("Enter the withdraw amount");
amount=Integer.parseInt(in.readLine());
balance=myBankRemote.withdraw(amount);
System.out.println("Balance is"+balance);
break;
case 3:
System.exit(0);
}}} catch (Exception ex) {
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
} }
14
OUTPUT:
C:\>cd bank
C:\bank>set CLASSPATH=C:\Sun\AppServer\lib\j2ee.jar
C:\bank>javac *.java
C:\bank>set APPCPATH=c:\bank\bankAPPClient.jar
C:\bank>set path=c:\Sun\AppServer\bin;
C:\bank>appclient -client bankAPP.ear -name bankClient -textauth
Banking Operations
1. Deposit
2. Withdraw
3. Exit
Enter ur choice: 1
Enter the deposit amount
1000
Total amount is6000
Banking Operations
1. Deposit
2. Withdraw
3. Exit
Enter ur choice: 2
Enter the withdraw amount
1000
Balance is5000
Banking Operations
1. Deposit
2. Withdraw
3. Exit
Enter ur choice: 3
RESULT:
Thus the program has been executed and all the banking operations were done
successfully.
15
Ex.No: 4
LIBRARY OPERATION USING EJB
AIM:
To write an EJB program to perform the library operations.
HARDWARE SPECIFICATIONS:
1.Mother Board : MSI2. Processor : AMD Athlon (64 bit)3. Hard Disk : 80 GB4. Ram : 640 MB5. Monitor :15’inch HCL6. Keyboard : HCL7. Mouse : HCL Optical Mouse
SOFTWARE SPECIFICATIONS:
1. Microsoft Visual Studio 20082. Net Beans 7.0
ALGORITHM:
Step 1: Start the program.
Step 2: Put all the required .java files in a folder bank.
Step 3: Set the classpath C:\Library>set
CLASSPATH=C:\Sun\AppServer\lib\j2ee.jar.
Step 4: Compile all the .java files C:\Library>javac *.java.
Step 5: Open the J2EE server Deployement Tool.
Step 6: Select new Application from file menu and give the application display
name and click ok.
Step 7: Select newEnterprise bean from the file menu and add the ejb class file
from edit contents.
Step 8: Select newApplication client from the file menu and add the client class
files from the edit contents.
Step 9: Select deploy from the tools menu.
Step 10: Open the dos window and enter into library folder as C:/Library.
Step 11: Set application path as C:/Library>set
16
APPCPATH=c:\Library\LibraryAPPClient.jar.
Step 12: Set path as C:/Library>set path=c:\Sun\AppServer\bin;
Step 13: Run the client using C:/Library>appclient -client LibraryAPP.ear -name
LibraryClient –textauth
Step 14: Stop the program.
17
PROGRAM:
LibraryHome.java
import javax.ejb.*;
import java.rmi.*;
public interface LibraryHome extends EJBHome
{
public Library create(String uname,String uid) throws
RemoteException,CreateException;
}
Library.java
import javax.ejb.*;
import java.rmi.*;
public interface Library extends EJBObject
{
public String issue(String bn,int nobook)throws RemoteException;
public String ret(String bn,int days)throws RemoteException;
}
LibraryBean.java
import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
public class LibraryBean implements SessionBean
{
String username;
String userid;
String bookname;
int nobook;
18
public void ejbCreate(String uname,String uid)
{
username=uname;
userid=uid;
}
public void ejbRemove()
{}
public void ejbActivate()
{}
public void ejbPassivate()
{}
public void setSessionContext(SessionContext ctx)
{}
public String issue(String bname,int nbook)
{
bookname=bname;
nobook=nbook;
if(nobook<=30)
return"Available AND &issued";
else
return "Not Available";
}
public String ret(String bname,int days)
{
bookname=bname;
if(days<30)
return"Returned without fine";
else
return" Returned with fine";
}
}
19
LibraryClient.java
import javax.ejb.*;
import javax.naming.*;
import java.io.*;
import javax.rmi.*;
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
public class LibraryClient
{
public static void main(String args[])throws Exception
{
Library myLibrary=null;
LibraryHome myLibraryHome=null;
try
{
InitialContext initial = new InitialContext();
String JNDIName="ejb/SimpleLibrary";
Object obj=initial.lookup(JNDIName);
myLibraryHome=(LibraryHome)PortableRemoteObject.narrow(obj,Librar
yHome.class);
int z,c1; String s,e,name,no,e1;
int nobook;
DataInputStream m=new DataInputStream(System.in);
System.out.println("Library Operation");
System.out.println("Enter username");
name=m.readLine();
System.out.println("Enter user ID");
no=m.readLine();
myLibrary=myLibraryHome.create(name,no);
while(true)
{ System.out.println("1.Issue");
20
System.out.println("\n2.Return");
System.out.println("\n3.Exit");
System.out.println("Enter ur choice");
z=Integer.parseInt(m.readLine());
switch(z)
{ case 1:
System.out.println("Enter Book name");
s=m.readLine();
System.out.println("Enter no of books required");
nobook=Integer.parseInt(m.readLine());
e=myLibrary.issue(s,nobook);
System.out.println(e);
break;
case 2:
System.out.println("Enter Book name");
s=m.readLine();
System.out.println("Enter days");
c1=Integer.parseInt(m.readLine());
e1=myLibrary.ret(s,c1);
System.out.println(e1);
break;
case 3:
myLibrary.remove();
System.exit(0);
break;
}
}
}
catch(Exception e)
{}
}
}
21
OUTPUT:
C:\library>set CLASSPATH=C:\Sun\AppServer\lib\j2ee.jar
C:\library>javac *.java
C:\library>set APPCPATH=C:\library\LibraryAppClient.jar
C:\library>set path=C:\Sun\AppServer\bin;
C:\library>appclient -client LibraryApp.ear -name LibraryClient -textauth
Library Operation
Enter username
mani
Enter user ID
123
Menu
1. Issue
2. Return
3. Exit
Enter ur choice
1
Enter Book name
JAVA
Enter no of books required
15
Available AND &issued
Menu
1. Issue
2. Return
3. Exit
Enter ur choice
2
Enter Book name
JAVA
Enter days
25
Returned without fine
22
Menu
1. Issue
2. Return
3. Exit
Enter ur choice
3
C:\library>
RESULT:
Thus the program has been executed and all the library operations were done
successfully.
23
Ex.No: 5
FILE OPERATIONS
AIM:
To write a visual basic program to perform the various file operations.
HARDWARE SPECIFICATIONS:
1.Mother Board : MSI2. Processor : AMD Athlon (64 bit)3. Hard Disk : 80 GB4. Ram : 640 MB5. Monitor :15’inch HCL6. Keyboard : HCL7. Mouse : HCL Optical Mouse
SOFTWARE SPECIFICATIONS:
1. Microsoft Visual Studio 20082. Net Beans 7.0
ALGORITHM:
Step 1: Start the program.
Step 2: Declare the necessary packages.
Step 3: Design the form with one Rich textbox and following buttons
Create
Read
Save
Copy
Delete
Step 4: Click the create button to crete a new file.
Step 5: Click the read button to get the file and display the contents.
Step 6: Click the save button the save the contents into the file.
Step 7: Click the copy button to copy the contents to another file.
Step 8: Click the delete button to delete the existing file.
Step 9: Stop the program.
24
PROGRAM:
Imports System.IO
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim opndlg As New OpenFileDialog
Dim Filearea As StreamReader
opndlg.Filter = "All Files(*.*)|*.*|TextFiles(*.txt)|*.txt"
opndlg.ShowDialog()
Filearea = New StreamReader(opndlg.FileName)
RichTextBox1.Text = Filearea.ReadToEnd
Filearea.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
Dim savdlg As New SaveFileDialog
Dim Filewri As StreamWriter
savdlg.Filter = "All Files(*.*)|*.*|TextFiles(*.txt)|*.txt"
savdlg.ShowDialog()
Filewri = New StreamWriter(savdlg.FileName)
Filewri.WriteLine(RichTextBox1.Text)
Filewri.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
Dim fs As FileStream
Dim Filename As String = "c:\sample.txt"
If File.Exists(Filename) Then
MsgBox("File Exists")
Else
fs = New FileStream(Filename, FileMode.Create, FileAccess.ReadWrite)
Dim byt() As Byte = System.Text.UTF8Encoding.UTF8.GetBytes("Richtextbox1.text")
fs.Write(byt, 0, byt.Length)
25
fs.close()
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button4.Click
Dim fname As String
fname = InputBox("Enter full path of delete filename")
If File.Exists(fname) Then
File.Delete(fname)
MsgBox("SUCESSFULLY DELETED")
Else
MsgBox("File was not available")
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button5.Click
Dim file1 As String = InputBox("Enter full path of sourcefle name")
Dim file2 As String = InputBox("Enter full path of destination(new file name)")
If Not File.Exists(file1) Then
MsgBox("File was not available")
Else
File.Copy(file1, file2)
MsgBox("sucessfully copied")
End If
End Sub
End Class
26
OUTPUT:
FORM 1:- CREATING A FILE
27
FORM 2:- SAVING THE FILE
28
FORM 3:- READING A FILE
29
FORM 4.1:- COPYING A FILE
30
FORM 4.2:- COPYING DESTINATION
31
FORM 5:- DELETING A FILE
RESULT:
Thus the program has been executed and all the file read and write operations were done
successfully.
32
Ex:No: 6
CURRENCY CONVERSION
AIM:
To write a program in VB.NET for currency conversion operation.
HARDWARE SPECIFICATIONS:
1.Mother Board : MSI2. Processor : AMD Athlon (64 bit)3. Hard Disk : 80 GB4. Ram : 640 MB5. Monitor :15’inch HCL6. Keyboard : HCL7. Mouse : HCL Optical Mouse
SOFTWARE SPECIFICATIONS:
1. Microsoft Visual Studio 20082. Net Beans 7.0
ALGORITHM:
Step1: Start the program.
Step2: Create a class.
Step3: Design a window with needed textboxes, combo box and buttons.
Step4: Write a coding for combo box to insert all the options based on currency
types.
Step5: Write a coding for textbox1 as to show the value of currency which is
selected in combo box.
Step6: Read the input in textbox2.
Step7: Write a coding for button1 as to calculate the amount.
Step8: Display the amount in textbox3.
Step9: Stop the program.
33
PROGRAM:
Public Class Form1
Dim ex, amt As Single
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
amt = ex * Val(TextBox2.Text)
TextBox3.Text = amt
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Button2.Click
End
End Sub
Private Sub ComboBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles ComboBox1.Click
ComboBox1.Items.Add("US DOLLAR")
ComboBox1.Items.Add("STERLING")
ComboBox1.Items.Add("DINAR")
ComboBox1.Items.Add("FRANC")
ComboBox1.Items.Add("EURO")
End Sub
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
Handles TextBox1.GotFocus
Select Case ComboBox1.Text
Case "US DOLLAR"
ex = 42.5
Case "STERLING"
ex = 71.3
Case "DINAR"
ex = 25.32
Case "FRANC"
34
ex = 31.58
Case "EURO"
ex = 41.58
End Select
TextBox1.Text = ex
End Sub
End Class
35
OUTPUT:
FORM 1:- CURRENCY CONVERTION
RESULT:
Thus the currency conversion program has been executed and completed successfully.
36
Ex.No: 7
ENCRYPTION AND DECRYPTION
AIM:
To write a visual basic program to perform the Encryption and Decryption operations.
HARDWARE SPECIFICATIONS:
1.Mother Board : MSI2. Processor : AMD Athlon (64 bit)3. Hard Disk : 80 GB4. Ram : 640 MB5. Monitor :15’inch HCL6. Keyboard : HCL7. Mouse : HCL Optical Mouse
SOFTWARE SPECIFICATIONS:
1. Microsoft Visual Studio 20082. Net Beans 7.0
ALGORITHM:
Step 1: Start the program.
Step 2: Declare the necessary packages.
Step 3: Design the form with Rich textbox and three buttons.
Step 4: In the encryption coding create a text file with access permission to write.
Step 5: Use CreateEncryptor to convert the text to Unicode Encoding.
Step 6: In the decryption coding open the file with the access permission to read.
Step 7: Use CreateDecryptor to convert the encoding into original text.
Step 8: Encrypted text can be read in the Rich textbox.
Step 9: Stop the program.
37
PROGRAM:
Imports System.IO
Imports System.Security.Cryptography
Imports System.Text
Public Class Form1
Inherits System.Windows.Forms.Form
Dim des As New DESCryptoServiceProvider
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim fs As New FileStream("C:\book.txt", FileMode.Create, FileAccess.Write)
Dim bytearrayinput As Byte() = New UnicodeEncoding().GetBytes(RichTextBox1.Text)
Dim desencrypt As ICryptoTransform = des.CreateEncryptor()
Dim cryptostream As New CryptoStream(fs, desencrypt, CryptoStreamMode.Write)
cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length)
cryptostream.Close()
RichTextBox1.Text = " "
MsgBox("Data is Encrypted")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
Dim fsread As New FileStream("c:\book.txt", FileMode.Open, FileAccess.Read)
Dim desdecrypt As ICryptoTransform = des.CreateDecryptor()
Dim cryptostreamdecr As New CryptoStream(fsread, desdecrypt,
CryptoStreamMode.Read)
RichTextBox1.Text = New StreamReader(cryptostreamdecr, New
UnicodeEncoding).ReadToEnd()
MsgBox("Data is Decrypted")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
Dim filearea As StreamReader
filearea = New StreamReader("c:\book.txt")
38
RichTextBox1.Text = filearea.ReadToEnd
filearea.Close()
End Sub
End Class
39
OUTPUT:
FORM 1:- ENCRYPTION
40
FORM 2:- DECRYPTION
RESULT:
Thus the encryption and decryption operation has been performed successfully.
41
Ex.No: 8
STUDENT DATABASE
AIM:
To write a Visual basic .Net Program to maintain Student databases.
HARDWARE SPECIFICATIONS:
1.Mother Board : MSI2. Processor : AMD Athlon (64 bit)3. Hard Disk : 80 GB4. Ram : 640 MB5. Monitor :15’inch HCL6. Keyboard : HCL7. Mouse : HCL Optical Mouse
SOFTWARE SPECIFICATIONS:
1. Microsoft Visual Studio 20082. Net Beans 7.0
ALGORITHM:
Step 1: Start the program.
Step 2: Create the Student database in MS Access with the needed fields.
Step 3: Design the form with necessary Textboxes and buttons.
Step 4: Connect the database by using the Provider
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\spstu.mdb"
Step 5: Enter the data and click the insert button then the data will be inserted
into the database.
Step 6: Specify the roll no in the input box corresponding data will be displayed.
Step 7: Data will be updated into the database by clicking the update button.
Step 8: Specify the roll no in the input box corresponding data will be deleted.
Step 9: Stop the program.
42
PROGRAM:
Public Class Form1
Dim con As New OleDb.OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=F:\spstu.mdb")
Dim selstu1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim rn, ag, na, cl
Dim strcmd As String
rn = TextBox1.Text
na = TextBox2.Text
ag = TextBox3.Text
cl = TextBox4.Text
con.Open()
strcmd = "insert into spstu(rollno,name,age,class)values(" & rn & " ,' " & na & " ',"
& ag & ",'" & cl & " ' ) "
Dim selstu As Data.OleDb.OleDbCommand = New
Data.OleDb.OleDbCommand(strcmd, con)
selstu.ExecuteNonQuery()
MsgBox("Record inserted")
con.Close()
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
TextBox4.Text = " "
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
con.Open()
Dim s As String
Dim no = InputBox("Enter the roll number to search")
s = "select * from spstu where rollno=" & no & " "
43
Dim selstu1 As Data.OleDb.OleDbCommand = New
Data.OleDb.OleDbCommand(s, con)
Dim dr As Data.OleDb.OleDbDataReader
dr = selstu1.ExecuteReader
Do While dr.Read
TextBox1.Text = dr.Item("rollno")
TextBox2.Text = dr.Item("name")
TextBox3.Text = dr.Item("age")
TextBox4.Text = dr.Item("class")
Loop
con.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
Dim no = TextBox1.Text
con.Open()
Dim na = TextBox2.Text
Dim s As String
s = " update spstu set name = ' " & na & " 'where rollno=" & no & " "
Dim selstu2 As Data.OleDb.OleDbCommand = New
Data.OleDb.OleDbCommand(s, con)
selstu2.ExecuteReader()
MsgBox("Record updated")
con.Close()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button4.Click
con.Open()
Dim temp
Dim no = InputBox("Enter the number to be deleted")
Dim selstu1 As Data.OleDb.OleDbCommand = New
44
Data.OleDb.OleDbCommand("delete from spstu where rollno=" & no & " ", con)
'Dim dr As Data.OleDb.OleDbDataReader
temp = selstu1.ExecuteReader()
MsgBox("Record deleted")
con.Close()
End Sub
End Class
45
OUTPUT:
FORM 1:- INSERTION
46
FORM 2.1:- DISPLAY
47
FORM 2.2:- DISPLAYED DETAILS
48
FORM 3:- UPDATION
49
FORM 4:- DELETION
RESULT:
Thus the student database program has been executed and completed successfully.
50
Ex.No: 9
STOCK MARKET EXCHANGE USING CORBA
AIM:
To write a java program to retrieve stock market exchange information using corba.
HARDWARE SPECIFICATIONS:
1.Mother Board : MSI2. Processor : AMD Athlon (64 bit)3. Hard Disk : 80 GB4. Ram : 640 MB5. Monitor :15’inch HCL6. Keyboard : HCL7. Mouse : HCL Optical Mouse
SOFTWARE SPECIFICATIONS:
1. Microsoft Visual Studio 20082. Net Beans 7.0
ALGORITHM:
Step 1: Start the program.
Step 2: Create the simplestocks.idl file.
Step 3: Write the implementation, server, and client coding.
Step 4: Create a new folder in C directory and save all the above files in that
folder.
Step 5: Compile the idl file using (idlj –fall –oldImplBase simplestocks.idl) in dos
window.
Step 6: Now compile all the java files by (javac *.java).
Step 7: Start the tnameserv and minimize the window.
Step 8: Run the server and client in separate windows.
Step 9: Save the program.
Step 10: Stop the program.
51
PROGRAM:
Simplestocks.idl
module simplestocks
{
interface stockmarket
{
float get_price(in string symbol);
};
};
Stockmarketimpl.java
import org.omg.CORBA.*;
import simplestocks.*;
public class stockmarketimpl extends _stockmarketImplBase
{
public float get_price(String symbol)
{
float price=0;
for(int i=0;i<symbol.length();i++)
{
price+=(int)symbol.charAt(i);
}
price/=5;
return price;
}
public stockmarketimpl()
{
super();
}
}
Stockmarketserver.java
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
52
import simplestocks.*;
public class stockmarketserver
{
public static void main(String args[])
{
try
{
ORB orb=ORB.init(args,null);
Stockmarketimpl d=new stockmarketimpl();
orb.connect(d);
org.omg.CORBA.Object
objRef=orb.resolve_initial_references("NameService");
NamingContext ncRef=NamingContextHelper.narrow(objRef);
NameComponent nc=new NameComponent("NASDAQ","");
NameComponent path[]={nc};
ncRef.rebind(path,(d));
System.out.println("stock market server is up and ready");
Thread.currentThread().join();
}
catch(Exception e)
{}
}
}
Stockmarketclient.java
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import simplestocks.*;
public class stockmarketclient
{
public static void main(String args[])
{
try
{
53
ORB orb=ORB.init(args,null);
org.omg.CORBA.Object
objRef=orb.resolve_initial_references("NameService");
NamingContext ncRef=NamingContextHelper.narrow(objRef);
NameComponent nc=new NameComponent("NASDAQ","");
NameComponent path[]={nc};
stockmarket market=stockmarketHelper.narrow(ncRef.resolve(path));
System.out.println("price of my company is"+market.get_price("b"));
}
catch(Exception e)
{}
}
}
54
OUTPUT:
C:\corba>idlj -fall -oldImplBase simplestocks.idl
C:\corba>javac *.java
C:\corba>tnameserv
Initial Naming Context:
IOR:000000000000002849444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e67436f
6e746578743a312e3000000000010000000000000058000101000000000e3139322e3136382e30
2e31353000042100000019afabcaff0000000238da7c4e000000080000000000000000010000000
000000100000001000000140000000000010020000000000001010000000000
TransientNameServer: setting port for initial object references to: 900
Ready.
Server Window:
C:\corba>java stockmarketserver
stock market server is up and ready
Client Window:
C:\corba>java stockmarketclient
price of my company is19.6
RESULT:
Thus the stock market program has been executed and completed successfully
55
Ex.No: 10
WEATHER FORECASTING USING CORBA
AIM:
To write java program to display the weather forecasting using corba.
HARDWARE SPECIFICATIONS:
1.Mother Board : MSI2. Processor : AMD Athlon (64 bit)3. Hard Disk : 80 GB4. Ram : 640 MB5. Monitor :15’inch HCL6. Keyboard : HCL7. Mouse : HCL Optical Mouse
SOFTWARE SPECIFICATIONS:
1. Microsoft Visual Studio 20082. Net Beans 7.0
ALGORITHM:
Step 1: Start the program.
Step 2: Create the simpletemps.idl file.
Step 3: Write the implementation, server, and client coding.
Step 4: Create a new folder in C directory and save all the above files in that
folder.
Step 5: Compile the idl file using (idlj –fall –oldImplBase simpletemps.idl) in dos
window.
Step 6: Now compile all the java files by (javac *.java).
Step 7: Start the tnameserv and minimize the window.
Step 8: Run the server and client in separate windows.
Step 9: Save the program.
Step 10: Stop the program.
56
PROGRAM:
Simpletemps.idl
module simpletemps
{
interface weatherforecast
{
string get_tmp(in float a);
};
};
Weatherforecastimpl.java
import org.omg.CORBA.*;
import simpletemps.*;
public class weatherforecastimpl extends _weatherforecastImplBase
{
public String get_tmp(float a)
{
String c;
if(a<0)
c="****Too cool****";
else if(a<=10)
c="**** cool****";
else if(a<=20)
c="**** Moderate****";
else if(a<=30)
c="**** Hot****";
else
c="****Too Hot****";
return c;
}
public weatherforecastimpl()
{
super();
57
}
}
Weatherforecastserver.java
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import simpletemps.*;
public class weatherforecastserver
{
public static void main(String args[])
{
try
{
ORB orb=ORB.init(args,null);
weatherforecastimpl d=new weatherforecastimpl();
orb.connect(d);
org.omg.CORBA.Object
objRef=orb.resolve_initial_references("NameService");
NamingContext ncRef=NamingContextHelper.narrow(objRef);
NameComponent nc=new NameComponent("NASDAQ","");
NameComponent path[]={nc};
ncRef.rebind(path,(d));
System.out.println("weather forecast server is up and ready");
Thread.currentThread().join();
}
catch(Exception e)
{}
}
}
Weatherforecastclient.java
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import simpletemps.*;
import java.io.*;
public class weatherforecastclient
58
{
public static void main(String args[])
{
try
{
System.out.println("Enter the temperature");
java.io.DataInputStream in=new java.io.DataInputStream(System.in);
float e=Float.parseFloat(in.readLine());
ORB orb=ORB.init(args,null);
org.omg.CORBA.Object
objRef=orb.resolve_initial_references("NameService");
NamingContext ncRef=NamingContextHelper.narrow(objRef);
NameComponent nc=new NameComponent("NASDAQ","");
NameComponent path[]={nc};
weatherforecast wthr=weatherforecastHelper.narrow(ncRef.resolve(path));
System.out.println("The climate is now : "+wthr.get_tmp(e));
}
catch(Exception e)
{}
}
}
59
OUTPUT:
tnameserv
C:\>cd corba
C:\corba>idlj -fall -oldImplBase simpletemps.idl
C:\corba>javac *.java
C:\corba>tnameserv
Initial Naming Context:
IOR:000000000000002849444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e67436f
6e746578743a312e3000000000010000000000000058000101000000000e3139322e3136382e30
2e
31353000043400000019afabcaff000000023a6c237700000008000000000000000001000000000
0
000100000001000000140000000000010020000000000001010000000000
TransientNameServer: setting port for initial object references to: 900
Ready.
Weatherforecast.Server
C:\>cd corba
C:\corba>java weatherforecastserver
C:\corba>java weatherforecastserver
weather forecast server is up and ready
Weatherforecast.Client
C:\corba>java weatherforecastclient
Enter the temperature
10
climate is**** cool****
C:\corba>java weatherforecastclient
Enter the temperature
50
climate is****Too Hot****
60
C:\corba>java weatherforecastclient
Enter the temperature
30
climate is**** Hot****
RESULT:
Thus the Weather Forecast program has been executed and completed successfully.
61