Solved

RMI does not compile!

Posted on 1998-05-15
7
174 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
Comment Utility
Adjusted points to 150
0
 
LVL 5

Expert Comment

by:fontaine
Comment Utility
What messages do you get?
0
 
LVL 5

Expert Comment

by:msmolyak
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:sdaxm11
Comment Utility
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
Comment Utility
Adjusted points to 200
0
 
LVL 5

Accepted Solution

by:
msmolyak earned 200 total points
Comment Utility
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
Comment Utility
ok it complies
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now