SQL Data Base Connection code

Imports System
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.SqlClient
Dim myConnection As System.Data.SqlClient.SqlConnection
Dim myCommand As System.Data.SqlClient.SqlCommand
Dim strSQL As String
myConnection = New SqlConnection("Data Source=MCANODE-102\MCA;Initial Catalog=master;Integrated Security=True")’master is database name,MCANODE_102\MCA hostname

        myConnection.Open()’Open the connection
        strSQL = "SELECT * FROM kar where id=12" ‘kar is tablename,id is field
        myCommand = New SqlCommand(strSQL, myConnection)
        Dim re As SqlDataReader = myCommand.ExecuteReader()
        While re.Read
            TextBox1.Text = re.GetString(2).ToString
        End While
       

        myConnection.Close()’Close the connection

RMI simple example




RMI simple example

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

public interface Calculator extends Remote
{
    public long addition(long a,long b) throws RemoteException;
    public long subtraction(long a,long b) throws RemoteException;
    public long multiplication(long a,long b) throws RemoteException;
    public long division(long a,long b) throws RemoteException;
}


Implementation

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class CalculatorImpl extends UnicastRemoteObject implements Calculator
{
    protected CalculatorImpl() throws RemoteException
    {
        super();
    }
    public long addition(long a, long b) throws RemoteException
    {
        return a+b;
    }
    public long subtraction(long a, long b) throws RemoteException
    {
        return a-b;
    }
    public long multiplication(long a, long b) throws RemoteException
    {
        return a*b;
    }
    public long division(long a, long b) throws RemoteException
    {
        return a/b;
    }
   
}



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

public interface Calculator extends Remote
{
    public long addition(long a,long b) throws RemoteException;
    public long subtraction(long a,long b) throws RemoteException;
    public long multiplication(long a,long b) throws RemoteException;
    public long division(long a,long b) throws RemoteException;
}


Server
import java.rmi.Naming;

public class CalculatorServer
{
    CalculatorServer()
    {
        try
        {
            Calculator c = new CalculatorImpl();
            Naming.rebind("rmi://localhost:1099/CalculatorService", c);
        }
        catch (Exception e)
        {
            System.out.println("Exception is : "+e);
        }
    }
    public static void main(String[] args)
    {
        new CalculatorServer();
    }
}


Client
import java.rmi.Naming;

public class CalculatorClient
{
    public static void main(String[] args)
    {
        try
        {
            Calculator c = (Calculator) Naming.lookup("//127.0.0.1:1099/CalculatorService");
            System.out.println("Addition : "+c.addition(10,5));
            System.out.println("Subtraction : "+c.subtraction(10,5));
            System.out.println("Multiplication :"+c.multiplication(10,5)); 
                    System.out.println("Division : "+c. division(10,5));
        }
        catch (Exception e)
        {
            System.out.println("Exception is : "+e);
        }
    }
}


Compilation

javac Calculator.java

javac CalculatorImpl.java

javac CalculatorServer.java

javac CalculatorClient.java

rmic  CalculatorImpl

start rmiregistry


java CalculatorServer

java CalculatorClient

output

Addition : 15
Subtraction : 5
Multiplication :50
Division : 2



Your IP Address is:

Browser: