Solved

RMI does not compile!

Posted on 1998-05-15
7
176 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…

770 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