Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

RMI does not compile!

Posted on 1998-05-15
7
Medium Priority
?
184 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 600 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

886 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