28, మార్చి 2012, బుధవారం

IN THIS POST I HAVE EXPLAINED THE CONCEPT HOW RMI CONCEPT WORKS WITH JAVA DATABASE CONNECTIVITY


BY USING RMI HERE I AM CONNECTING TO THE DATABASE FOR RETRIEVING INFORMATION
Prg-1   Interface design
Import java.rmi.*;
Public  ineface dbinterface extends Remote
{
public String getName(int x)  throws RemoteException;
}

prg-2  Server design
Import java.rmi.server.*;
Import java.rmi.registry.*;
Public class dbserver extends UnicastRemoteObject implements dbiinterface
{
dbserver() throws RemoteException
{}
public String getName(int x) throws RemoteException
{
try
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection c=DriverManager.getConnection(“  Jdbc:Odbc:sample ” ,” scott   ”,    ” tiger ” );
Stament stmt=c.createStatement();
String command=” select from emp where empno=   ”+x;
ResultSet rs=stmt.execuateQuery(command);
rs.next();
String s=rs.getString(2);
rs.close();
stmt.close();
c.close();
return(s);
}
catch(Exception e){ return “ NO DATA ”}
}
public static void main(String args[])
{
try{
DBServer dbs=new DBServer();
Naming.rebind(“DATABASE”,dbs);
System.out.println(“\n the DATABASESERVER STARTED”);
}
catch(Exception e){}
}}


prg-3 Client program
import java.rmi.*;
class DBClint
{
public static void main(String args[])
{
try
{
DBInterface dbi=new (DBInterface)Naming.lookup(“DATABASE”);
String s=dbi.getName(7788);
System.out.println(“\n the name is ”+s);
}
catch(Exception e){}
}}

కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి