Results 1 to 2 of 2
  1. #1
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    236
    Rep Power
    3

    Default In RMI Security-policy Making problem while run it

    Good Morning To All!

    I am very happy to appear after long time in our forums Sir,

    now i try to run am RMI project (I did it in my College days) with jdk.1.4

    i set every thing. But while i run it. it not allowing me to do any more action..,

    It is an small software (workbench) to create All kinds of Database actions like

    Create,
    Update,
    Delete
    &
    Insert
    on Different kinds of Databases like
    ms-access,
    Oracle,
    MySQL,
    etc..,



    My error message is

    access denied (java.util.proprtypermission java.rmi.server.codebase write)


    My Interface Class is

    Java Code:
    package Server;
    
    import java.rmi.*;
    import java.sql.*;
    import java.util.*;
    public interface   DataBase extends Remote
    {
    	public int connection(String userName,String Password,String DataBase)throws RemoteException;
    	public void setAutoCommitTable()throws RemoteException;
    	public void commitTable()throws RemoteException;
    	public Vector getTableFields(String table)throws RemoteException;
    	public Vector getAllTables() throws RemoteException;
    	public int createTable(String query)throws RemoteException;
    	public int insertTable(String query) throws RemoteException;
    	public Vector getColumns(String table) throws RemoteException;
    	public Vector getRows(String query) throws RemoteException;
    	public int updateTable(String query) throws RemoteException;
    	public int alterTable(String query) throws RemoteException;
    	public int dropTable(String query) throws RemoteException;
    	public int deleteTable(String query)throws RemoteException;
    
        public void connection()throws RemoteException;
    
        public void selectTable(String query)throws RemoteException;
    My Implementation class is

    Java Code:
    package Server;
    
    import Client.*;
    import java.sql.*;
    import java.rmi.*;
    import java.rmi.server.*;
    import java.util.*;
    public class DataBaseImpl implements DataBase
    {
    	Connection c;
    	Statement s;
    	ResultSet rs;
    	ResultSetMetaData rsm;
    	String userName=null;
    	String dataBase=null;
    	public DataBaseImpl()
    	{
    		c=null;
    		s=null;
    		rs=null;
    		rsm=null;
    	}
    	public int  connection(String userName,String passWord,String dataBase)throws RemoteException
    	{
    		try
    		{
    			
    			
    			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");	
    			System.out.println("Driver is loaded");
    			c=DriverManager.getConnection("jdbc:odbc:administrator");
    			System.out.println("Connection is Established");
    			
    			s=c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    			String query="select DataSourceName from administrator where UserName='"+userName+"' and PassWord='"+passWord+"' and DataBase='"+dataBase+"'";
    			System.out.println(query);
    			rs=s.executeQuery(query); 
    			this.userName=userName;
    			this.dataBase=dataBase;
    			if(rs.next())
    			{
    				String dataSourceName=rs.getString(1);
    				System.out.println(dataSourceName);
    				c.close();
    				c=null;
    				if(dataBase.equalsIgnoreCase("msaccess"))
    				{
    					c=DriverManager.getConnection("jdbc:odbc:"+dataSourceName);	
    					System.out.println("access driver is connected");
    				}
    				else if(dataBase.equalsIgnoreCase("My SQL"))
    				{
    					Class.forName("com.mysql.jdbc.Driver");
    					System.out.println("My SQL driver is loaded");
    					c=DriverManager.getConnection("jdbc:mysql://localhost:3306/readmain",userName,passWord);
    
    					//c=DriverManager.getConnection("jdbc:odbc:MyOracleDataBase","scott","tiger");
    					System.out.println("My SQL driver is connected");
    				}
    				
    				System.out.println("Connection is Established");
    				s=c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    
    				return 1;
    			}			
    			else
    			{	rs.close();
    				return 0;
    			}
    			
    			//DatabaseMetaData dbmd=c.getMetaData();
    			//return dbmd;
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();
    			return 0;
    		}
    
    	}
    	public Vector getAllTables() 
    	{
    		try
    		{
    			DatabaseMetaData dbmd=c.getMetaData();
    			
    			rs=null;
    			if(dataBase.equalsIgnoreCase("My SQL"))
    				rs=dbmd.getTables(null,userName.toUpperCase(),null,new String[]{"TABLE","VIEW"});	
    			else if(dataBase.equalsIgnoreCase("msaccess"))
    				rs=dbmd.getTables(null,null,null,new String[]{"TABLE","VIEW"});	
    			Vector v=new Vector();
    			while(rs.next())
    			{
    				
    				v.addElement(rs.getString(3));
    				
    
    			}
    			
    			return v;
    	
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();
    			
    		}
    		return null;
    	}
    	public Vector getTableFields(String table)
    	{
    		try
    		{	
    			rs=s.executeQuery(table);
    			rsm=rs.getMetaData();
    			int colSize= rsm.getColumnCount();
    			Vector v=new Vector();
    			String st;
    			for (int i=1;i<=colSize;i++)
    		        {   	
    				st=(rsm.getColumnTypeName(i)).toLowerCase();
    				v.addElement(st);
    				
    			}
    			
    			rs.close();
    			return v;
    		}	
    		catch(Exception e)
    		{
    			e.printStackTrace();
    		}
    		return null;
    	}
    	public Vector getColumns(String table)
    	{
    		try
    		{
    			rs=s.executeQuery(table);
    			rsm=rs.getMetaData();
    			int colSize= rsm.getColumnCount();
    			Vector v=new Vector();
    			String st1=null;
    			for (int i=1;i<=colSize;i++)
    		        {   	
    				st1=rsm.getColumnName(i).toUpperCase();
    				v.addElement(st1);
    				
    			}
    			
    			rs.close();
    			return v;
    		}	
    		catch(Exception e)
    		{
    			e.printStackTrace();
    		}
    		return null;
    	}
    	public void setAutoCommitTable()
    	{
    		try
    		{
    			c.setAutoCommit(true);
    		}
    		catch(Exception e)
    		{e.printStackTrace();}
    	}
    	public void commitTable()
    	{
    		try
    		{
    			c.commit();
    		}
    		catch(Exception e)
    		{e.printStackTrace();}
    	}
    	public int createTable(String query)
    	{
    		try
    		{
    			if(!s.execute(query))
    			{
    				
    				return 1;
    			}
    			else
    			{
    				
    				return 0;
    			}
    		}
    		catch(Exception e)
    		{
    			
    			e.printStackTrace();
    			return 0;
    		}		
    							
    	}
    	public int insertTable(String query)
    	{
    		try
    		{
    			if(s.executeUpdate(query)>0)
    			{	
    				return 1;
    			}
    			else
    			{
    				return 0;
    			}			
    	
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();
    		}
    		return 0;		
    							
    	}
    	public Vector getRows(String query)
    	{
    		try
    		{
    			
    			String ColumnName="     ";
    			
    			rs=s.executeQuery(query);
    			rsm=rs.getMetaData();
    			int count=rsm.getColumnCount();
    			
    			
    			for (int i=1;i<=count;++i)
    				ColumnName=ColumnName+rsm.getColumnName(i)+"     ";
    			System.out.println(ColumnName+"\n");
    			
    			
    			Vector v=new Vector();
    			
    			while(rs.next())
    			{	Vector vv=new Vector();
    				
    				for(int i=1;i<=count;i++)
    				{	
    					int columntype=rsm.getColumnType(i);
    					switch(columntype)				
    					{
    						case 12:
    						case 1:	
    							String text=rs.getString(i);
    							
    							vv.addElement(text);
    							break;
    								
    						case 93:
    						case 91:
    							java.sql.Date date=rs.getDate(i);
    							
    							vv.addElement(date);
    							break;
    						case 2:
    							Double dou= new Double(rs.getDouble(i));							
    							vv.addElement(dou);
    							break;
    						case 8 :int number=rs.getInt(i); 
    							
    							Integer num=new Integer(number);
    							vv.addElement(num);
    							break;
    					}
    					
    				}
    				System.out.println();
    				v.addElement(vv);	
    			
    			}
    			rs.close();
    			return v;			
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();
    		}		
    		return null;
    							
    	}
    	public int deleteTable(String query)
    	{
    		try
    		{
    			if(s.executeUpdate(query)>0)
    				return 1;
    			else
    				return 0;
    	
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();
    		}
    		return 10;		
    							
    	}	
    	public int updateTable(String query)
    	{
    		try
    		{
    			if(s.executeUpdate(query)>0)
    				return 1;
    			else
    				return 0;
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();
    		}		
    		return 0;
    						
    	}
    	public int alterTable(String query)
    	{
    		try
    		{
    			if(s.executeUpdate(query)>0)
    			{	
    				return 1;
    			}
    			else
    			{	
    				return 0;
    			}	
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();
    		}		
    		return -1;				
    	}
    	public int dropTable(String query)
    	{
    		try
    		{
    			
    			if(!s.execute(query))
    			{
    				return 1;
    			}
    			else
    			{
    				return 0;
    			}
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();
    			return 0;
    		}		
    							
    	}	
    public static void main(String args[])
    	{
                if (System.getSecurityManager() == null) {
    System.setSecurityManager(new RMISecurityManager());
    }
    		try
    		{
    			DataBaseImpl ob=new DataBaseImpl();
    			UnicastRemoteObject.exportObject(ob);
    			Naming.rebind("rmi://localhost:1099/ReDataBase",ob);//5001
    			System.out.println("DataBase Ready");
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();
    		}
    	}
    
        public void connection() {
            throw new UnsupportedOperationException("Not supported yet.");
        }
        public void selectTable(String query) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
    My Lan Class is

    Java Code:
    package Server;
    
    import java.io.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.*;
    import javax.swing.*; 
    import javax.swing.tree.*; 
    import java.rmi.*;
    import java.rmi.server.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.util.*;
    public class DataBases extends JFrame implements ActionListener
    {
    	Container g;
    	JMenuBar mb;
    	JMenu file,edit,sql,table,result,window,help;
    	JMenuItem open,save,saveas,exit,export,impor;
    	JMenuItem cut,copy,paste,selectall;
    	JMenuItem execute,commit,roll,auto;
    	JMenuItem create,drop,alter,insert,select,update,delete,condb,discondb;
    	JMenuItem coopy,selectal;
    	JMenuItem toolbar,cleip,cleop;
    	JMenuItem helpp,show,about; 
     	DefaultTableModel dtb;
    	JTable restable;
    	JSeparator js;
    	ImageIcon im;
    	JToolBar jtb;
    	JButton op,sa,cu,co,pa,ex,com,rol,upd,hel,his;
    	JTextArea jta;
    	JTree jt;
    	DefaultMutableTreeNode dmt,parenttable,parentview;
    	DefaultTreeModel dm;
    	JScrollPane jsp,jsp1;
    	JPanel jp,jp1,jp3 ;
    	
    	DataBase x=null;
    	
    	LogonWin lw=null;
    	TCreation tc=null;
    	TInsertion ti=null;
    	TSelection ts=null;
    	TUpdate tu=null;
    	TDelete td=null;
    	TDrop tdrop=null;
    	TAlter ta=null;
            
    	JOptionPane jo1;
    	Vector v=null;
    	JTable report;
    	public String database=null;
    	
    	DataBases ()
    	{	super("DataBase");
    		g=this.getContentPane();
    		designs();
    		
    		lw=new LogonWin(this);
    		
    		setSize(870,570);
    		g.setLayout(new BorderLayout());
    		im=new ImageIcon();
    		
    
    	}	
    	boolean connections(String username,String password,String database)
    	{
    	try
    		{	
    			this.database=database;
    			System.setProperty("java.security.policy","all.policy");
    			System.setSecurityManager(new RMISecurityManager());
    			System.setProperty("java.rmi.server.codebase","http://localhost:8080/examples/");
    			x=(DataBase)Naming.lookup("rmi://localhost:1099/ReDataBase");	
    			
    			int flag=x.connection(username,password,database);
    			
    			if (flag==1)
    			{
    				jo1.showMessageDialog(this,"DataBase Successfully connected","Connecting Database...",  jo1.INFORMATION_MESSAGE);	
    				v=new Vector();
    				v=x.getAllTables();
    				return true;
    			}
    			else
    			{
    				jo1.showMessageDialog(this,"DataBase Doesn't Connected","Connection Error",  jo1.WARNING_MESSAGE);	
    				return false;
    			}
    			
    	      }
    		catch(Exception e1)
    		{
    			jo1.showMessageDialog(this,e1.getMessage(),"Connection Error",  jo1.WARNING_MESSAGE);	
    		}
    		return false;
    	}
    	void designs()
    	{
    	//***********************************CODING FOR MENU'S******************************************
    		
    		mb=new JMenuBar();
    		setJMenuBar(mb);
    		dmt=new DefaultMutableTreeNode("Database");
    		parenttable=new DefaultMutableTreeNode("Tables");
    		parentview=new DefaultMutableTreeNode("Views");
    		dmt.add(parenttable);
    		dmt.add(parentview);
    		parenttable.setAllowsChildren(true);
    		dm=new DefaultTreeModel(dmt);
    		dm.reload(dmt);
    
    		file=(JMenu)mb.add(new JMenu("File"));
    		file.setMnemonic('F');
    		edit=(JMenu)mb.add(new JMenu("Edit"));
    		edit.setMnemonic('E');
    		sql=(JMenu)mb.add(new JMenu("SQL"));
    		sql.setMnemonic('S');
    		table=(JMenu)mb.add(new JMenu("DBA"));
    		table.setMnemonic('D');
    		result=(JMenu)mb.add(new JMenu("Result"));
    		result.setMnemonic('R');
    		window=(JMenu)mb.add(new JMenu("WIndow"));
    		window.setMnemonic('W');
    		help=(JMenu)mb.add(new JMenu("Help"));
    		help.setMnemonic('H');
    /********************CODING FOR MENU ITEMS*************************/		
    		open=(JMenuItem)file.add(new JMenuItem("Open",im=new ImageIcon("open.gif")));
    		open.setAccelerator(KeyStroke.getKeyStroke('O',Event.CTRL_MASK,false));
    		save=(JMenuItem)file.add(new JMenuItem("Save",im=new ImageIcon("save.gif")));
    		save.setAccelerator(KeyStroke.getKeyStroke('S',Event.CTRL_MASK,false));
    		saveas=(JMenuItem)file.add(new JMenuItem("Save As"));
    		js=(JSeparator)file.add(new JSeparator());
    		export=(JMenuItem)file.add(new JMenuItem("Exprot"));
    		impor=(JMenuItem)file.add(new JMenuItem("Import"));
    		js=(JSeparator)file.add(new JSeparator());
    		exit=(JMenuItem)file.add(new JMenuItem("Exit",im=new ImageIcon("close.gif")));
    		exit.setAccelerator(KeyStroke.getKeyStroke('Q',Event.ALT_MASK,false));
    
    		cut=(JMenuItem)edit.add(new JMenuItem("Cut",im=new ImageIcon("cut.gif")));
    		cut.setAccelerator(KeyStroke.getKeyStroke('X',Event.CTRL_MASK,false));
    		copy=(JMenuItem)edit.add(new JMenuItem("Copy",im=new ImageIcon("copy.gif")));
    		copy.setAccelerator(KeyStroke.getKeyStroke('C',Event.CTRL_MASK,false));
    		paste=(JMenuItem)edit.add(new JMenuItem("Paste",im=new ImageIcon("paste.gif")));
    		paste.setAccelerator(KeyStroke.getKeyStroke('V',Event.CTRL_MASK,false));
    		js=(JSeparator)edit.add(new JSeparator());
    		selectall=(JMenuItem)edit.add(new JMenuItem("Select All"));
    		
    		execute=(JMenuItem)sql.add(new JMenuItem("Execute",im=new ImageIcon("execute.gif")));
    		js=(JSeparator)sql.add(new JSeparator());
    		commit=(JMenuItem)sql.add(new JMenuItem("Commit",im=new ImageIcon("commit.gif")));
    		roll=(JMenuItem)sql.add(new JMenuItem("Rollback",im=new ImageIcon("rol.gif")));
    		js=(JSeparator)sql.add(new JSeparator());
    		auto=(JMenuItem)sql.add(new JMenuItem("AutoCommit"));
    
    		create=(JMenuItem)table.add(new JMenuItem("Create",im=new ImageIcon("create.gif")));
    		js=(JSeparator)table.add(new JSeparator());
    		drop=(JMenuItem)table.add(new JMenuItem("Drop"));			
    		js=(JSeparator)table.add(new JSeparator());
    		alter=(JMenuItem)table.add(new JMenuItem("Alter"));			
    		js=(JSeparator)table.add(new JSeparator());
    		insert=(JMenuItem)table.add(new JMenuItem("Insert"));			
    		js=(JSeparator)table.add(new JSeparator());
    		select=(JMenuItem)table.add(new JMenuItem("Select"));			
    		js=(JSeparator)table.add(new JSeparator());
    		update=(JMenuItem)table.add(new JMenuItem("Update"));			
    		js=(JSeparator)table.add(new JSeparator());
    		delete=(JMenuItem)table.add(new JMenuItem("Delete"));			
    		js=(JSeparator)table.add(new JSeparator());
    		condb=(JMenuItem)table.add(new JMenuItem("Connect to DataBase",im=new ImageIcon("connect.gif")));			
    		js=(JSeparator)table.add(new JSeparator());
    		discondb=(JMenuItem)table.add(new JMenuItem("Disconnect to DataBase"));			
    
    		coopy=(JMenuItem)result.add(new JMenuItem("Copy",im=new ImageIcon("copy.gif")));
    		coopy.setAccelerator(KeyStroke.getKeyStroke('W',Event.CTRL_MASK,false));
    		selectal=(JMenuItem)result.add(new JMenuItem("SelectAll"));
    		selectal.setAccelerator(KeyStroke.getKeyStroke('Q',Event.CTRL_MASK,false));
    
    		cleip=(JMenuItem)window.add(new JMenuItem("ClearInput"));		
    		cleop=(JMenuItem)window.add(new JMenuItem("ClearOutput"));
    		js=(JSeparator)window.add(new JSeparator());
    		toolbar=(JMenuItem)window.add(new JMenuItem("ToolBar"));
    
    		helpp=(JMenuItem)help.add(new JMenuItem("HelpTopics",im=new ImageIcon("help.gif")));
    		show=(JMenuItem)help.add(new JMenuItem("ShowSystem",im=new ImageIcon("info.gif")));
    		about=(JMenuItem)help.add(new JMenuItem("About RDBE",im=new ImageIcon("about.gif")));
    
    //**************************************CODING FOR TOOLBAR****************************************		
    
    		jp3=new JPanel();
    		jtb=new JToolBar();
    
    		op=(JButton)jtb.add(new JButton("",im=new ImageIcon("ope.gif")));
     		sa=(JButton)jtb.add(new JButton("",im=new ImageIcon("sav.gif")));
    		cu=(JButton)jtb.add(new JButton("",im=new ImageIcon("cu.gif")));
    		co=(JButton)jtb.add(new JButton("",im=new ImageIcon("cop.gif")));
    		pa=(JButton)jtb.add(new JButton("",im=new ImageIcon("pas.gif")));
    		ex=(JButton)jtb.add(new JButton("",im=new ImageIcon("exe.gif")));
    		upd=(JButton)jtb.add(new JButton("",im=new ImageIcon("Up.gif")));
    		co=(JButton)jtb.add(new JButton("",im=new ImageIcon("co.gif")));
    		rol=(JButton)jtb.add(new JButton("",im=new ImageIcon("ro.gif")));
    		hel=(JButton)jtb.add(new JButton("",im=new ImageIcon("he.gif")));
    		jp3.add(jtb);
    		
    		g.add(jp3,BorderLayout.NORTH);
    		
    //****************************************coding for Jtree****************************************
    
    		 
    		jp1=new JPanel(new GridLayout(1,0,5,5));
    		jt=(JTree)g.add(new JTree(dm));	
    		
    		jsp=new JScrollPane(jt);
    		jp1.add(jsp);
    		
    		g.add(jp1,BorderLayout.WEST);
    		
    
    		
    		
    //**********************************************coding for Right Areas***************************
    
    		jp=new JPanel(null);
    		jta=(JTextArea)g.add(new JTextArea(5,5));
    		jsp=new JScrollPane(jta,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    		JLabel label=new JLabel("Query");
    		label.setBounds(10,5,40,20);
    		jp.add(label);
    		jsp.setBounds(0,40,650,100);
    		jp.add(jsp);
    		report =new JTable();
    		JScrollPane jsp1=new JScrollPane(report,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    		JLabel label1=new JLabel("Result");
    		label1.setBounds(10,5,40,120);
    		jp.add(label1);
    		jsp1.setBounds(0,190,650,250);
    		
    		jp.add(jsp1);
    		g.add(jp,BorderLayout.CENTER);
    		
    				 				
    //********************TO ADD LISTENERS*************************
    		open.addActionListener(this);
    		save.addActionListener(this);
    		saveas.addActionListener(this);
    		exit.addActionListener(this);
    		cut.addActionListener(this);
    		copy.addActionListener(this);
    		paste.addActionListener(this);
    		selectall.addActionListener(this);
    		execute.addActionListener(this);
    
    		create.addActionListener(this);
    		alter.addActionListener(this);;
    		drop.addActionListener(this);
    		insert.addActionListener(this);
    		select.addActionListener(this);
    		update.addActionListener(this);
    		delete.addActionListener(this);
    		condb.addActionListener(this);
    		discondb.addActionListener(this);
    		
    		coopy.addActionListener(this);
    		selectal.addActionListener(this);
    		
    		helpp.addActionListener(this);
    		
    		op.addActionListener(this);
    		sa.addActionListener(this);
    		cu.addActionListener(this);
    		co.addActionListener(this);
    		pa.addActionListener(this);
    
    		
    		setVisible(true);
    	}
    /*********************** EXECUTE SOME REMOTE METHOD ******************/	
    	public void executeTree()
    	{
    		try
    		{
    			v=x.getAllTables();
    			Object o[]=v.toArray();
    			parenttable.removeAllChildren();
    			for(int i=0;i<o.length;i++)
    			{
    				
    				DefaultMutableTreeNode node=new DefaultMutableTreeNode((String)o[i] );
    				parenttable.add(node);
    				Vector v1=x.getColumns("select * from "+(String)o[i]);
    				Vector v2=x.getTableFields("select *  from "+o[i]);
    				if(v1==null || v2==null)
    					continue;
    				Object o1[]=v1.toArray();
    				Object o2[]=v2.toArray();
    				for(int j=0;j<o1.length;j++)
    				{
    					//System.out.println(o1[j]);
    					DefaultMutableTreeNode node1=new DefaultMutableTreeNode((String)o1[j] );
    					node.add(node1);
    					node1.add(new DefaultMutableTreeNode((String)o2[j]));				
    					
    				}
    				
    				
    			}
    			((DefaultTreeModel)jt.getModel()).reload((DefaultMutableTreeNode)jt.getModel().getRoot());
    			jt.expandRow(1);
    		}
    		catch(Exception e)
    		{
    			jo1.showMessageDialog(this,e.getMessage(),"Creation Error",  jo1.WARNING_MESSAGE);	
    		}
    	}
    	public int executeCreateQuery(String query)
    	{
    		try
    		{
    			int flag=x.createTable(query);
    			v=x.getAllTables();
    			executeTree();
    			return flag;
    		}
    		catch(Exception e)
    		{
    			jo1.showMessageDialog(this,e.getMessage(),"Creation Error",  jo1.WARNING_MESSAGE);	
    		}
    		return 0;
    	}
    	public void executeDropQuery(String query)
    	{
    		try
    		{
    			int flag=x.dropTable(query);
    			//System.out.println(query+flag);
    			if(flag==0)
    			{
    				jo1.showMessageDialog(this,"Table Dropped Successfully","Table Droption",  jo1.PLAIN_MESSAGE);	
    				v=x.getAllTables();
    				executeTree();
    				executeTree();
    			}
    			else
    			{
    				jo1.showMessageDialog(this,"Error in Table dropping...","Already Dropped" , jo1.ERROR_MESSAGE);	
    			}
    		}
    		catch(Exception e)
    		{
    			jo1.showMessageDialog(this,e.getMessage(),"Droption Error",  jo1.WARNING_MESSAGE);	
    		}
    	}
    	public int executeAlterQuery(String query)
    	{
    		try
    		{
    			int flag=0;
    			x.alterTable(query);
    			return flag;
    		}
    		catch(Exception e)
    		{
    			jo1.showMessageDialog(this,e.getMessage(),"Alteration Error",  jo1.WARNING_MESSAGE);	
    		}
    		return 0;
    	}
    	public void executeInsertQuery(String query)
    	{
    		try
    		{
    			int flag=x.insertTable(query);
    			if(flag>0)
    			{
    				jo1.showMessageDialog(this,"Table Inserted Successfully","Table Insertion",  jo1.PLAIN_MESSAGE);	
    			}
    			else
    			{
    				jo1.showMessageDialog(this,"Error in Table Insertion...","Already Dropped" , jo1.ERROR_MESSAGE);	
    			}
    		}
    		catch(Exception e)
    		{
    			jo1.showMessageDialog(this,e.getMessage(),"Insertion Error",  jo1.WARNING_MESSAGE);	
    		}
    	}
    	public int executeUpdateQuery(String query)
    	{
    		
    		try
    		{
    			int flag=x.updateTable(query);
    			
    			
    			return flag;
    			
    		}
    		catch(Exception e)
    		{
    			jo1.showMessageDialog(this,e.getMessage(),"Updation Error",  jo1.WARNING_MESSAGE);	
    		}
    		return -1;
    	}
    	public int executeDeleteQuery(String query)
    	{
    		try
    		{
    			int flag=x.deleteTable(query);
    			
    			
    			return flag;
    			
    		}
    		catch(Exception e)
    		{
    			jo1.showMessageDialog(this,e.getMessage(),"Deletion Error",  jo1.WARNING_MESSAGE);	
    		}
    		return -1;
    	}
    	
    	public void executeSelectQuery(String query)
    	{
    		try
    		{
    			Vector v1=x.getRows(query);
    			Vector v2=x.getColumns(query);
    			
    			report.setModel(new DefaultTableModel(v1,v2));
    			report.setGridColor(new Color(210,110,100));
    			report.setEnabled(false);
    			
    			report.setFont(new Font("SansSerif",Font.BOLD,12));
    			JTableHeader jth=report.getTableHeader();
    			jth.setFont(new Font("SansSerif",Font.BOLD,12));
    			jth.setForeground(Color.red);
    			
    		
    			
    		}
    		catch(Exception e)
    		{
    			jo1.showMessageDialog(this,e.getMessage(),"Seletion Error",  jo1.WARNING_MESSAGE);	
    		}
    		
    	}
    	public Vector executeColumnsQuery(String query)
    	{
    		try
    		{
    			Vector v2=x.getColumns(query);
    			
    			return v2;
    		}
    		catch(Exception e)
    		{
    			jo1.showMessageDialog(this,e.getMessage(),"Columns selection Error",  jo1.WARNING_MESSAGE);	
    		}
    		return null;
    	
    	}
    	public Vector executeRowsQuery(String query)
    	{
    		try
    		{
    			Vector v2=x.getRows(query);
    			return v2;
    		}
    		catch(Exception e)
    		{
    			jo1.showMessageDialog(this,e.getMessage(),"RowSeletion Error",  jo1.WARNING_MESSAGE);		
    		}
    		return null;
    	
    	}
    	public Vector getTableFields(String table)
    	{
    		try
    		{
    			Vector vv=x.getTableFields(table);
    			return vv;
    		}
    		catch(Exception e)
    		{
    			jo1.showMessageDialog(this,e.getMessage(),"Table Fields Error",  jo1.WARNING_MESSAGE);	
    		}	
    		return null;
    	}
    //*********************************Designing Over************************************************************]
    /**************************** MENUS AND BUTTONS ACTIONS**********/
    	public void actionPerformed(ActionEvent ae)
    	{
    		if(ae.getSource()==open)
    		{
    			JFileChooser jfc=new JFileChooser();
    			
    			jfc.setDialogType(JFileChooser.OPEN_DIALOG);
    			byte buf[]=new byte[64];
    			jta.setText("");
    			int r=jfc.showDialog(this,"Open");
    			if(r==JFileChooser.APPROVE_OPTION)
    			{
    				File f=jfc.getSelectedFile();
    				if(f.isAbsolute())
    				{
    					try{
    					InputStream in=new FileInputStream(f);
    					int nbytes=-1;
    					while((nbytes=in.read(buf))>0)
    					{
    						
    						 String s=(new String(buf,0,nbytes));
    						jta.setText(jta.getText()+s);
    					}}catch(Exception e){}
    				
    				}
    			}
    			
    		}
    		if(ae.getSource()==save)
    		{
    			JFileChooser jfc=new JFileChooser();
    			jfc.setDialogType(JFileChooser.SAVE_DIALOG);
    			int r=jfc.showDialog(this,"Save" );
    			if(r==JFileChooser.APPROVE_OPTION)
    			{
    				
    				
    				try{
    					String fname=jfc.getSelectedFile().getAbsolutePath();
    					FileWriter fw=new FileWriter(fname);
    					fw.write(jta.getText());
    					fw.flush();
    				    }catch(Exception e){}
    				
    				
    			}
    			
    		}
    		if(ae.getSource()==saveas)
    		{
    			JFileChooser jfc=new JFileChooser();
    			jfc.setDialogType(JFileChooser.SAVE_DIALOG);
    			int r=jfc.showDialog(this,"Save AS");
    			if(r==JFileChooser.APPROVE_OPTION)
    			{
    				
    				
    				try{
    					String fname=jfc.getSelectedFile().getAbsolutePath();
    					FileWriter fw=new FileWriter(fname);
    					fw.write(jta.getText());
    					fw.flush();
    				    }catch(Exception e){}
    				
    				
    			}
    			
    		}
    		if(ae.getSource()==exit)
    		{
    			
    			System.exit(0);
    		}
    		if(ae.getSource()==cut)
    		{
    			int start=jta.getSelectionStart();
    			int end=jta.getSelectionEnd();
    			jta.cut();
    		}
    		if(ae.getSource()==copy)
    		{
    			jta.copy();
    		}
    		if(ae.getSource()==paste)
    		{
    			jta.paste();
    		}
    		if(ae.getSource()==selectall)
    		{
    						
    			jta.selectAll();	
    		}
    		if(ae.getSource()==execute)
    		{
    			String query=jta.getText().trim();
    			if(query.trim()==null)
    			{
    				jo1.showMessageDialog(this,"Enter the Query","Enter...." , jo1.ERROR_MESSAGE);	
    			}
    			else
    			{
    			try
    			{
    			String findQuery=(query.substring(0,3));
    			
    			if(findQuery.equalsIgnoreCase("cre"))
    			{		int flag=x.createTable(query);
    				if(flag==1)
    				{
    					executeTree();
    					jo1.showMessageDialog(this,"Table Created Successfully","Table Creation",  jo1.PLAIN_MESSAGE);	
    				}
    				else
    				{
    					jo1.showMessageDialog(this,"Error in Table Creation","Already Exists" , jo1.ERROR_MESSAGE);	
    				}
    			}
    			
    
    			else if(findQuery.equalsIgnoreCase("ins"))
    			{	
    				int flag=x.insertTable(query);
    				if(flag==1)
    				{
    					jo1.showMessageDialog(this,"Table data are inserted Successfully","Table Insertion",  jo1.PLAIN_MESSAGE);	
    				}
    				else
    				{
    					jo1.showMessageDialog(this,"Error in Query","Verify...." , jo1.ERROR_MESSAGE);	
    				}
    					
    			}
    			else if(findQuery.equalsIgnoreCase("sel"))
    			{	Vector v1=	x.getRows(query);
    					
    			}
    			else if(findQuery.equalsIgnoreCase("upd"))
    			{
    				int flag=x.updateTable(query);
    				if(flag==1)
    				{
    					jo1.showMessageDialog(this,"Table data are inserted Successfully","Table Insertion",  jo1.PLAIN_MESSAGE);	
    				}
    				else
    				{
    					jo1.showMessageDialog(this,"Error in Query","Verify...." , jo1.ERROR_MESSAGE);	
    				}
    			}
    			
    			else if(findQuery.equalsIgnoreCase("alt"))
    			{
    				if(((String)(database)).equalsIgnoreCase("msaccess"))
    				{
    					jo1.showMessageDialog(this,"Access doesn't support in Alter Query....","Alter...." , jo1.ERROR_MESSAGE);		
    				}	
    				else if(((String)(database)).equalsIgnoreCase("My SQL"))
    				{		
    					int flag=x.alterTable(query);
    					if(flag==1)
    					{
    						jo1.showMessageDialog(this,"Table is altered Successfully","Table Alteration",  jo1.PLAIN_MESSAGE);	
    					}
    					else
    					{
    						jo1.showMessageDialog(this,"Error in Query","Verify...." , jo1.ERROR_MESSAGE);	
    					}
    				}		
    			}	
    			else if(findQuery.equalsIgnoreCase("dro"))
    			{	
    				int flag=x.dropTable(query);
    				
    				if(flag==1)
    				{
    					executeTree();
    					jo1.showMessageDialog(this,"Table is droped Successfully","Table Droption",  jo1.PLAIN_MESSAGE);	
    				}
    				else
    				{
    					jo1.showMessageDialog(this,"Error in Query","Verify...." , jo1.ERROR_MESSAGE);	
    				}
    
    							
    			}	
    			else if(findQuery.equalsIgnoreCase("del"))
    			{	
    				int flag=x.deleteTable(query);
    				if(flag==1)
    				{
    					jo1.showMessageDialog(this,"Table data are deleted Successfully","Table Deletion",  jo1.PLAIN_MESSAGE);	
    				}
    				else
    				{
    					jo1.showMessageDialog(this,"Error in Query","Verify...." , jo1.ERROR_MESSAGE);	
    				}
    	
    			}
    			else
    			{
    				jo1.showMessageDialog(this,"Invalid Query","Verify...." , jo1.ERROR_MESSAGE);	
    			}
    			v=x.getAllTables();
    			}
    			
    			catch(Exception e)
    			{
    				jo1.showMessageDialog(this,e.getMessage(),"Creation Error",  jo1.WARNING_MESSAGE);	
    			}
    			}//else
    		}
    		if(ae.getSource()==create)
    		{
    			
    			tc=new TCreation(this);
    			tc.setLocation(200,110);
    	 		tc.setTitle("Table Creation");
    			tc.setSize(350,360);
    			tc.show();
    			
    		}
    		if(ae.getSource()==insert)
    		{
    			ti=new TInsertion(this);
    			ti.setLocation(175,100);
    			ti.setSize(400,400);
    			
    			ti.doConnect1(v);
    			ti.show();
    			
    		}
    		if(ae.getSource()==select)
    		{
    			ts=new TSelection(this);
    			ts.setLocation(175,100);
    			ts.setSize(400,400);
    			ts.doConnect1(v);
    			ts.show();
    			
    		}
    		if(ae.getSource()==update)
    		{
    			tu=new TUpdate(this);
    			tu.setLocation(175,100);
    			tu.setSize(400,400);
    			tu.doConnect1(v);
    			tu.show();
    		}
    		if(ae.getSource()==delete)
    		{
    			td=new TDelete(this);
    			td.setLocation(175,100);
    			td.setSize(400,400);
    			td.doConnect1(v);
    			td.show();
    		}
    		if(ae.getSource()==drop)
    		{
    			tdrop=new TDrop(this);
    			tdrop.setLocation(175,100);
    			tdrop.setSize(400,400);
    			tdrop.show();
    			tdrop.doConnect1(v);
    			
    		}
    		if(ae.getSource()==alter)
    		{
    			if(((String)(database)).equalsIgnoreCase("msaccess"))
    			{
    				jo1.showMessageDialog(this,"Access doesn't support in Alter Query....","Alter...." , jo1.ERROR_MESSAGE);		
    			}	
    			else if(((String)(database)).equalsIgnoreCase("My SQL"))
    			{
    				ta=new TAlter(this);
    				ta.setLocation(175,100);
    				ta.setSize(400,400);
    				ta.show();
    				ta.doConnect1(v);
    			}
    		}
    		if(ae.getSource()==condb)
    		{
    			lw=null;
    			lw=new LogonWin(this);
    					
    			jt=(JTree)g.add(new JTree(dm));	
    		
    			jsp=new JScrollPane(jt);
    			jp1.add(jsp);
    			g.add(jp1,BorderLayout.WEST);
    			executeTree();
    			
    			
    			
    		}
    		if(ae.getSource()==discondb)
    		{
    			System.exit(0);
    		}
    		if(ae.getSource()==helpp)
    		{
    			Help help=new Help();
    		}	
    //************************************for toolbar selection************************************
    		 
    		if(ae.getSource()==op)
    		{
    			JFileChooser jfc=new JFileChooser();
    			jfc.setDialogType(JFileChooser.OPEN_DIALOG);
    			byte buf[]=new byte[64];
    			jta.setText("");
    			int r=jfc.showDialog(this,"Open");
    			if(r==JFileChooser.APPROVE_OPTION)
    			{
    				File f=jfc.getSelectedFile();
    				if(f.isAbsolute())
    				{
    					try{
    					InputStream in=new FileInputStream(f);
    					int nbytes=-1;
    					while((nbytes=in.read(buf))>0)
    					{
    						
    						 String s=(new String(buf,0,nbytes));
    						jta.setText(jta.getText()+s);
    					}}catch(Exception e){}
    				
    				}
    			}
    			
    		}
    		if(ae.getSource()==sa)
    		{
    			JFileChooser jfc=new JFileChooser();
    			jfc.setDialogType(JFileChooser.SAVE_DIALOG);
    			int r=jfc.showDialog(this,"Save AS");
    			if(r==JFileChooser.APPROVE_OPTION)
    			{
    				
    				
    				try{
    					String fname=jfc.getSelectedFile().getAbsolutePath();
    					FileWriter fw=new FileWriter(fname);
    					fw.write(jta.getText());
    					fw.flush();
    				    }catch(Exception e){}
    				
    				
    			}
    			
    		}
    		 
    		if(ae.getSource()==cu)
    		{
    			int start=jta.getSelectionStart();
    			int end=jta.getSelectionEnd();
    			jta.cut();
    		}
    		if(ae.getSource()==co)
    		{
    			jta.copy();
    		}
    		if(ae.getSource()==pa)
    		{
    			jta.paste();
    		}
    		 
    
    	}
    //************************MAIN CLASS ****************************
    }
    class TestDataBases
    {
    	public static void main(String arg[])
    	{
    		new DataBases();
    	}
    
    }
    My Client Class is

    Java Code:
    package Server;
    
    import Client.*;
    import java.rmi.*;
    import java.io.*;
    class client
    {
    	public static void main(String args[])
    	{
    		try
    		{
    			System.setProperty("java.security.policy","all.policy");
    			System.setSecurityManager(new RMISecurityManager());
    			System.setProperty("java.rmi.server.codebase","http://localhost:8080/examples/");
    			DataBase x=(DataBase)Naming.lookup("rmi://localhost:1099/ReDataBase");//("rmi://E-SOFT-PC:1099/DataBases");	
    			DataInputStream dis=new DataInputStream(System.in);
    			x.connection();
    			System.out.println("DataBase connected");
    			char c;
    			
    			do
    			{
    			System.out.println("choose   1=>create Table   2=>Insert table  \n  3=>select  4=>delete   5=>update\n6=>Alter ");	
    			c=(char)System.in.read();
    			System.out.println("Enter the Query  : ");
    			dis.readLine();
    			String query=dis.readLine();
    			switch(c)
    			{
    				case '1':	x.createTable(query);
    						break;
    	
    				case '2': 	x.insertTable(query);	
    						break;
    
    				case '3': 	x.selectTable(query);
    						break;
    						
    				case '4':	x.deleteTable(query);
    						break;
    				
    				case '5': 	x.updateTable(query);
    						break;
    				
    				case '6':	x.alterTable(query);
    						break;
    				case '7':	x.dropTable(query);
    						break;
    			
    			}
    		}while(c!='8');
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();	
    		}
    
    		
    	}
    }
    My LogonWin class is

    Java Code:
    package Server;
    
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    public class LogonWin extends JFrame implements ActionListener
         {
    	Container g;
    	progressBar pb;
    	JPanel panel1,panel2,panel3;
    	JLabel jlabel1,jlabel2;
    	JLabel jlabel6,jlabel7,jlabel8;
    	JComboBox jcbox1;
    	JTextField jtf1;
    	JPasswordField jpf1;
    	JButton Connect,Cancel;
    	Color c1,c2;
    	JOptionPane jo1;
    	DataBases data;
    	
    	public LogonWin(DataBases data)
    	{
    		
    		g=this.getContentPane();
    		setTitle("Logon...");
    		setSize(350,250);
    		setLocation(200,170);
    		this.data=data;
    		
    		addPanel1();
    		addPanel2();
    		addPanel3();
    		getLayeredPane().setBackground(Color.red);
    		setVisible(true);
    	}
    	public void addPanel1()
    	{
    		panel1=new JPanel(new GridLayout(1,1,5,5));
    		jlabel1=new JLabel("BackEnd");
    		jcbox1=new JComboBox();	 
    		
    		
    		jcbox1.addItem("MsAccess");
    		jcbox1.addItem("Oracle");
    		jcbox1.addItem("SQL Server");
    		jcbox1.addItem("My SQL");
    		jcbox1.addItem("SyBase");
    		jcbox1.addItem("PointBase");
    		jcbox1.addActionListener(this);
    		panel1.add(jlabel1);
    		panel1.add(jcbox1);
    		panel1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),""));
    		panel1.setBorder(new TitledBorder(""));
    		g.add("North",panel1);
    	}
    	public void addPanel2()
    	{
    		panel2=new JPanel(new GridLayout(4,2,15,15));
    		Color c4=new Color(0,0,254);
    		panel2.add(new JLabel());
    		panel2.add(new JLabel());
    		jlabel1=new JLabel("              User Name");
    		jlabel2=new JLabel("              Password");
    		
    		jtf1=new JTextField();
    		jpf1=new JPasswordField();
    		jtf1.setForeground(c4);jpf1.setForeground(c4);
    		
    		panel2.add(jlabel1);panel2.add(jtf1);
    		panel2.add(jlabel2);panel2.add(jpf1);
    		panel2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),""));
    		panel2.setBorder(new TitledBorder(""));
    		
    	
    		g.add("Center",panel2);		
    	     }
    	public void addPanel3()
    	{
    		panel3=new JPanel(new GridLayout(1,5,5,5));
    		jlabel6=new JLabel("");
    		jlabel7=new JLabel("");
    		jlabel8=new JLabel("");
    		Connect=new JButton("Sign");
    		Cancel=new JButton("Cancel");
    		c1=new Color(0,108,0);
    		c2=new Color(102,0,0);
    		Connect.setForeground(c1);Connect.setBackground(Color.white);
    		Cancel.setForeground(c2);Cancel.setBackground(Color.white);
    		Connect.addActionListener(this);
    		Cancel.addActionListener(this);
    		panel3.add(jlabel6);
    		panel3.add(Connect);
    		panel3.add(jlabel7);
    		panel3.add(Cancel);
    		panel3.add(jlabel8);
    		panel3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),""));
    		panel3.setBorder(new TitledBorder(""));
    		g.add("South",panel3);		
    
    	}
    	public void actionPerformed(ActionEvent ae)
    	{
    		boolean flag;
    		if(ae.getSource()==Connect)
    		{
    			String database=(String)jcbox1.getSelectedItem();
    			String username=jtf1.getText().trim();
    			String password=jpf1.getText().trim();
    			if(username!=null&&password!=null)
    			{	
    				flag=data.connections(username,password,database);
    				if(flag)
    				{	
    					pb=null;
    					pb=new progressBar(data);
    					hide();
    				}
    				else
    				{
    					JOptionPane.showMessageDialog(this,"Please Enter Valid UserName (or) Password","Access denied",  JOptionPane.WARNING_MESSAGE);
    					jtf1.setText(null);
    					jpf1.setText(null);
    				}		
    			}
    			else
    			{
    			JOptionPane.showMessageDialog(this,"Please Enter  UserName (or) Password","Access denied",  JOptionPane.WARNING_MESSAGE);	
    			}
    		}
    		if(ae.getSource()==Cancel)
    		{
    			setVisible(false);
    		}
    		if(ae.getSource()==jcbox1)
    		{
    			jtf1.setText(null);
    			jpf1.setText(null);
    		}
    	}
    }
    And i have other supported Insert ,Update, Delete Classes also

    This is my policy file
    Java Code:
    /* AUTOMATICALLY GENERATED ON Fri Oct 05 11:16:41 IST 2012*/
    /* DO NOT EDIT */
    
    grant codeBase "http://localhost:8080/examples/" {
      permission java.security.AllPermission;
    };
    what i have to do..,

    Guide me please..,

    Thank you sir..,
    Last edited by raj.mscking@gmail.com; 10-05-2012 at 08:44 AM.
    - Raj

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: In RMI Security-policy Making problem while run it

    Do you really think anyone here will go through about 1000 lines of code?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Applet with jdbc and mysql security problem
    By 1224 in forum Java Applets
    Replies: 3
    Last Post: 01-31-2012, 12:50 PM
  2. Security Manager and Policy Files
    By Aaron D in forum New To Java
    Replies: 0
    Last Post: 09-25-2011, 09:14 PM
  3. Java Security Policy
    By divot in forum Advanced Java
    Replies: 1
    Last Post: 11-16-2010, 03:23 AM
  4. Djava.security.policy=applet.policy
    By willemjav in forum Java Applets
    Replies: 1
    Last Post: 03-09-2008, 01:57 AM
  5. Djava.security.policy=applet.policy
    By willemjav in forum NetBeans
    Replies: 0
    Last Post: 03-09-2008, 01:09 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •