Welcome To Uday Satya Blog

111-116 PROGRAMS



111  Program to Demonstrate Database Meta Data

import java.sql.*;

public class JDBCDBMetaDataDemo
{
public static void main(String[]args) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:MyDSN1","scott","tiger");
//create a DB metadata object
DatabaseMetaData dbm=con.getMetaData();
//String[] tabtypes={"TABLES"};
ResultSet tabrs=dbm.getTables(null,null,null,"TABLE");
while(tabrs.next())
{
System.out.println(tabrs.getString("TABLE_NAME"));
}
con.close();
}
}


















112  Program to Demonstrate Add Interface


import java.util.*;
import java.rmi.*;
public interface RMIAddInterface extends java.rmi.Remote
{
  int add(int a,int b ) throws RemoteException;
}



113   Program to Demonstrate Add S erver

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
public class RMIAddServer
{
 public static void main(String[] args) throws Exception
  {
      if(System.getSecurityManager() == null)
      {
       System.setSecurityManager( new RMISecurityManager() );
      }
      RMIAddImpl myObject = new RMIAddImpl( "MYADDSERVER" );
      System.out.println( "RMI Server ready..." );
  }
}











114  Program to add Client

import java.rmi.*;
import java.rmi.registry.*;
public class RMIAddClient
{
  public static void main(String[] args)
  {
    try
    {
      if(System.getSecurityManager() == null)
      {
       System.setSecurityManager( new RMISecurityManager() );
      }
RMIAddInterface a = (RMIAddInterface)Naming.lookup("rmi://localhost/MYADDSERVER");
      System.out.println( "The sum is:"+a.add(2,2));
    }
    catch( Exception e )
    {
      System.out.println( e );
    }
   }
}















115  implementation for the interface

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
public class RMIAddImpl extends UnicastRemoteObject implements RMIAddInterface
{
public RMIAddImpl( String name ) throws RemoteException
  {
    try  {
      Naming.rebind( name, this );
    }
    catch( Exception e )
    {
      System.out.println( e );
    }
  }
public int add( int a,int b )
  {
        return (a+b);
  }
}




116  Create a Policy to Allow Permission for  Everyone

grant {
      // Allow everything
      permission java.security.AllPermission;
};
etaData rsmd = rs.getMetaData();
for(int i=0; i< rsmd.getColumnCount();i++)
{

0 comments:

Post a Comment