Solved

RMI does not compile!

Posted on 1998-05-15
7
177 Views
Last Modified: 2013-12-29
i have been trying to get this porgram to work but some how it does not want to compile
basicly the program is a three tier JDBC program.
i am using JDK 1.1.5
could some pls have a look
thanks!!

the program is
**********************interface **********************************88
import java.rmi.*;

public interface out extends java.rmi.Remote
{
public Vector data(String SQLSearch) throws java.rmi.RemoteException;
}


**************************server side*****************************************
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.sql.*;
import java.util.*;


public class outImpl extends UnicastRemoteObject implements out{

private String SQL;

  public outImpl (String s) throws java.rmi.RemoteException {
    super();
  SQL=s;                                    
                                                            }     // end of constructor
 
 
public Vector data(String SQLSearch) throws Remote.Exception {
     
      public static ResultSet rs;
       public Vector results;  
      private  boolean more;
      
      String url = "jdbc:odbc:project";
       query = "select * from company_job where title like"+SQLSearch;
        
      try {

                  // Load the jdbc-odbc bridge driver
                  Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
            
            }                  // end of try
 

        catch(Exception ex){
      //setError("I am not doing anything because "+ex);
      return;
                  }            // catch expection

      

      try{
      Vector results=new Vector();
      Connection con= DriverManager.getConnection (url, "", "");
      Statement stmt = con.createStatement();
             ResultSet rs =stmt.executeQuery(query);
      
      
       boolean more = rs.next();
     

       while (more) {
        String s=rs.getString(5);
      //java.io.InputStream Notes=rs.getAsciiStream("Notes");
      String k=rs.getString(8);
      String text=s;
      String text1=k;
        results.addElement(text);
      results.addElement(text1);
        more = rs.next();
         
      }     // end of while
      
      stmt.close();
      con.close();
      return(data.results);
               } // end of try

      catch(SQLException ex){
      //setError("SQLException:"+ex);
      throw new IllegalArgumentException("Data " +" not found");
                        }                  // catch statment

       
      }  // data


 




 
  public static void main(String args[]) {
   
    // Create and install a security manager
   
    System.setSecurityManager(new RMISecurityManager());
 

 
    try {
      outImpl obj = new outImpl("Results");
      Naming.rebind("Results", obj);
      System.out.println("outServer bound in registry");
          
      }  //end of try
      

       catch (Exception e) {
      System.out.println("outServer err: " + e.getMessage());
      e.printStackTrace();
          
         } // end of catch


  } // end of public main

}  // end of class


*************************client side*******************************

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
//import java.applet.Applet;
import java.sql.*;
import java.util.*;
import java.rmi.*;


/*
  modify by katt on 13 feb
   ver 1.0
 */





public class outClient extends Applet implements  Runnable{

      private Thread worker;
      public static Vector queryResults;
      private String message="Initializing";
      public static ResultSet rs;
       public Vector results;
      public static int currpos;
          public static int      maxrows;
      private  boolean more;
      public static int x;
      


      //********************layout*****************
      Label label1;
      TextField txtSearch;
      Button btnSearch;
      Button btnNext;
      Button btnClear;
      Button btnPrev;
      //*******************end of layout****************



      String query;
public synchronized void start(){
      
            if (worker==null){
            message ="connecting to databse";
            worker=new Thread(this);
            worker.start();
                        }
                        }//end start

public void run(){
          
      
      

      // ********************create button*************************
      label1=new Label("Enter Search :");
        label1.setFont(new Font("Dialog",Font.PLAIN,10));
        add(label1);
        label1.reshape(insets().left + 6,insets().top + 7,78,13);
      
      
      txtSearch=new TextField(10);
        txtSearch.setFont(new Font("Dialog",Font.PLAIN,10));
        add(txtSearch);
        txtSearch.reshape(insets().left + 96,insets().top + 7,84,19);
      

      btnSearch=new Button("Search");
        btnSearch.setFont(new Font("Dialog",Font.PLAIN,10));
        add(btnSearch);
      btnSearch.reshape(insets().left + 272,insets().top + 7,60,26);  
      
      btnClear=new Button("Clear");
        btnClear.setFont(new Font("Dialog",Font.PLAIN,10));
        add(btnClear);
      btnClear.reshape(insets().left + 335,insets().top + 7,60,26);  

      btnNext=new Button("Next");
        btnNext.setFont(new Font("Dialog",Font.PLAIN,10));
        add(btnNext);
      btnNext.reshape(insets().left + 272,insets().top + 400,60,26);  

      btnPrev=new Button("Previous");
        btnPrev.setFont(new Font("Dialog",Font.PLAIN,10));
        add(btnPrev);
      btnPrev.reshape(insets().left + 210,insets().top + 400,60,26);  
      //***************And on the 7th day, god rested from creating************      



      
      //**************Me listen to do something*****************
            btnSearch.addActionListener( new ActionListener()
              { public void actionPerformed( ActionEvent e )
                    { btnSearchClicked(); } } );
            
      btnClear.addActionListener( new ActionListener()
              { public void actionPerformed( ActionEvent e )
                    { btnClearClicked(); } } );

      btnNext.addActionListener( new ActionListener()
              { public void actionPerformed( ActionEvent e )
                    { btnNextClicked(); } } );

      btnPrev.addActionListener( new ActionListener()
              { public void actionPerformed( ActionEvent e )
                    { btnPrevClicked(); } } );
      //**************Me say do nothing important really********



            }// end or run
public void btnPrevClicked(){
            currpos--;
            repaint();}

public void btnNextClicked(){
      
      
      
       if ( currpos + 1 <= maxrows ) {
             
            repaint();            
       
                       } // end of if
     else {
       currpos = maxrows;
     //repaint();
      }


}//end next click
      

//***********************Search*****************************


       public void btnSearchClicked()
             {   String bSearch = txtSearch.getText();
             try {
                        out obj = (out)Naming.lookup("//" +
                                getCodeBase().getHost() + "/Results");
                           //results(obj.data(bSearch));
                  //results=out.data(bSearch);
                  results=out.data(bSearch);
                     } catch (Exception e) {
                        System.out.println("out exception: " +
                                e.getMessage());
                        e.printStackTrace();
                                  }
            
      maxrows = results.size();
      currpos=0;

      setResults(results);
      
      
      //}// end of try statment


      /*catch(SQLException ex){
      setError("SQLException:"+ex);
                        }// catch statment
      */
      }// button clicked end






//*******************end of search*************************




      
      public synchronized void paint(Graphics g){
      
      if (queryResults==null){
      g.drawString(message,30,50);
      return;
                        }
      
      if (txtSearch.getText()==null){
      String Empty="Pls enter search query";
      g.drawString(Empty,30,50);
      return;
                        }
      
      
      
      g.drawString("Jobs:",60,50);
      int y=70;
      

            x=0;
            while( currpos <maxrows || x<=2 ){      
            String text =(String)queryResults.elementAt(currpos);      
            g.drawString(text,60,y);
            y=y+30;
            currpos++;
            x++;
                              }

      }
      


       public void
    btnClearClicked(){
                  
            txtSearch.setText("");
            query="";
            //repaint();
            results.removeAllElements();      
            queryResults.removeAllElements();      
            
            currpos=1;}
            





private synchronized void setError(String mess){
      queryResults=null;
      message=mess;
      worker=null;
      repaint();
      }

private synchronized void setResults(Vector results){
      queryResults=results;
      worker=null;
      repaint();
      }


}// end of class
0
Comment
Question by:sdaxm11
  • 4
  • 2
7 Comments
 

Author Comment

by:sdaxm11
ID: 1221036
Adjusted points to 150
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1221037
What messages do you get?
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1221038
In the interface add
import java.util.Vector;

In the server code, procedure

public Vector data(String SQLSearch) throws Remote.Exception {
           
    public static ResultSet rs;
      public Vector results;    
    private  boolean more;

Change Remote.Exception to RemoteException

Remove all the modifiers from you method variables (or make them instance/class variables). Method variables cannot be public or static. Only the ones defined in the class can have those modifiers.

You seem to have many more problems in you code, but why don't you fix those first.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:sdaxm11
ID: 1221039
ok i have tried that(i works too)  but basicly i need the program to compile, if anyone can do this i will raise the points 200


0
 

Author Comment

by:sdaxm11
ID: 1221040
Adjusted points to 200
0
 
LVL 5

Accepted Solution

by:
msmolyak earned 200 total points
ID: 1221041
200 points it is.

-----------
out.java
-----------
    import java.rmi.*;
    import java.util.Vector;

    public interface out extends java.rmi.Remote
    {
    public Vector data(String SQLSearch) throws java.rmi.RemoteException;
    }


-----------
outImpl.java
-----------
    import java.rmi.*;
    import java.rmi.server.UnicastRemoteObject;
    import java.sql.*;
    import java.util.*;


    public class outImpl extends UnicastRemoteObject implements out
    {

    private String SQL;

      public outImpl (String s) throws java.rmi.RemoteException
      {
        super();
        SQL=s;
      }     // end of constructor


    public Vector data(String SQLSearch) throws RemoteException
    {

    String url = "jdbc:odbc:project";
    String query = "select * from company_job where title like"+SQLSearch;

    try {

    // Load the jdbc-odbc bridge driver
    Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");

    }      // end of try


            catch(Exception ex){
    //setError("I am not doing anything because "+ex);
    return null;
    } // catch expection



    try{
    Vector results=new Vector();
    Connection con= DriverManager.getConnection (url, "", "");
    Statement stmt = con.createStatement();
            ResultSet rs =stmt.executeQuery(query);


    boolean more = rs.next();


    while (more) {
            String s=rs.getString(5);
    //java.io.InputStream Notes=rs.getAsciiStream("Notes");
    String k=rs.getString(8);
    String text=s;
    String text1=k;
            results.addElement(text);
    results.addElement(text1);
            more = rs.next();

    }     // end of while

    stmt.close();
    con.close();
    return(results);
        } // end of try

    catch(SQLException ex){
    //setError("SQLException:"+ex);
    throw new IllegalArgumentException("Data " +" not found");
    } // catch statment


    }  // data


      public static void main(String args[]) {

        // Create and install a security manager

        System.setSecurityManager(new RMISecurityManager());



        try {
          outImpl obj = new outImpl("Results");
          Naming.rebind("Results", obj);
          System.out.println("outServer bound in registry");

    }  //end of try


    catch (Exception e) {
          System.out.println("outServer err: " + e.getMessage());
          e.printStackTrace();

             } // end of catch


      } // end of public main

    }  // end of class



-----------
outClient.java
-----------


    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    //import java.applet.Applet;
    import java.sql.*;
    import java.util.*;
    import java.rmi.*;


    /*
      modify by katt on 13 feb
       ver 1.0
     */





    public class outClient extends Applet implements  Runnable{

    private Thread worker;
    public static Vector queryResults;
    private String message="Initializing";
    public static ResultSet rs;
      public Vector results;
    public static int currpos;
         public static int      maxrows;
    private  boolean more;
    public static int x;



    //********************layout*****************
    Label label1;
    TextField txtSearch;
    Button btnSearch;
    Button btnNext;
    Button btnClear;
    Button btnPrev;
    //*******************end of layout****************



    String query;
    public synchronized void start(){

    if (worker==null){
    message ="connecting to databse";
    worker=new Thread(this);
    worker.start();
    }
    }//end start

    public void run(){




    // ********************create button*************************
    label1=new Label("Enter Search :");
            label1.setFont(new Font("Dialog",Font.PLAIN,10));
            add(label1);
            label1.reshape(insets().left + 6,insets().top + 7,78,13);


    txtSearch=new TextField(10);
            txtSearch.setFont(new Font("Dialog",Font.PLAIN,10));
            add(txtSearch);
            txtSearch.reshape(insets().left + 96,insets().top + 7,84,19);


    btnSearch=new Button("Search");
            btnSearch.setFont(new Font("Dialog",Font.PLAIN,10));
            add(btnSearch);
    btnSearch.reshape(insets().left + 272,insets().top + 7,60,26);

    btnClear=new Button("Clear");
            btnClear.setFont(new Font("Dialog",Font.PLAIN,10));
            add(btnClear);
    btnClear.reshape(insets().left + 335,insets().top + 7,60,26);

    btnNext=new Button("Next");
            btnNext.setFont(new Font("Dialog",Font.PLAIN,10));
            add(btnNext);
    btnNext.reshape(insets().left + 272,insets().top + 400,60,26);

    btnPrev=new Button("Previous");
            btnPrev.setFont(new Font("Dialog",Font.PLAIN,10));
            add(btnPrev);
    btnPrev.reshape(insets().left + 210,insets().top + 400,60,26);
    //***************And on the 7th day, god rested from creating************




    //**************Me listen to do something*****************
    btnSearch.addActionListener( new ActionListener()
             { public void actionPerformed( ActionEvent e )
             { btnSearchClicked(); } } );

    btnClear.addActionListener( new ActionListener()
             { public void actionPerformed( ActionEvent e )
             { btnClearClicked(); } } );

    btnNext.addActionListener( new ActionListener()
             { public void actionPerformed( ActionEvent e )
             { btnNextClicked(); } } );

    btnPrev.addActionListener( new ActionListener()
             { public void actionPerformed( ActionEvent e )
             { btnPrevClicked(); } } );
    //**************Me say do nothing important really********



    }// end or run
    public void btnPrevClicked(){
    currpos--;
    repaint();}

    public void btnNextClicked(){



    if ( currpos + 1 <= maxrows ) {

    repaint();

          } // end of if
         else {
           currpos = maxrows;
         //repaint();
    }


    }//end next click


    //***********************Search*****************************


    public void btnSearchClicked()
           {   String bSearch = txtSearch.getText();
    try {
                            out obj = (out)Naming.lookup("//" +
                                    getCodeBase().getHost() + "/Results");
                          //results(obj.data(bSearch));
    //results=out.data(bSearch);
    results=obj.data(bSearch);
             } catch (Exception e) {
                            System.out.println("out exception: " +
                                    e.getMessage());
                            e.printStackTrace();
                     }

    maxrows = results.size();
    currpos=0;

    setResults(results);


    //}// end of try statment


    /*catch(SQLException ex){
    setError("SQLException:"+ex);
    }// catch statment
    */
    }// button clicked end






    //*******************end of search*************************





    public synchronized void paint(Graphics g){

    if (queryResults==null){
    g.drawString(message,30,50);
    return;
    }

    if (txtSearch.getText()==null){
    String Empty="Pls enter search query";
    g.drawString(Empty,30,50);
    return;
    }



    g.drawString("Jobs:",60,50);
    int y=70;


    x=0;
    while( currpos <maxrows || x<=2 ){
    String text =(String)queryResults.elementAt(currpos);
    g.drawString(text,60,y);
    y=y+30;
    currpos++;
    x++;
    }

    }



    public void
        btnClearClicked(){

    txtSearch.setText("");
    query="";
    //repaint();
    results.removeAllElements();
    queryResults.removeAllElements();

    currpos=1;}






    private synchronized void setError(String mess){
    queryResults=null;
    message=mess;
    worker=null;
    repaint();
    }

    private synchronized void setResults(Vector results){
    queryResults=results;
    worker=null;
    repaint();
    }


    }// end of class
0
 

Author Comment

by:sdaxm11
ID: 1221042
ok it complies
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question