Solved

RMI does not compile!

Posted on 1998-05-15
7
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Print Rhino Java Array in Javascript 1 59
Java Eclipse Loop 3 50
program arguments vs VM arguments 4 58
Overriding a method 3 14
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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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:
Suggested Courses

752 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