• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URGENT : how to connect the database to the GUI

 
rb
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am posting this for the second time.
Please if you have any ideas, help.
I have no idea of how to connect (create a database instance) for my user's GUI. Because of the security manager that has to be installed to run the database client, I am lauching the client using Runtime.exec(java -Djava.security .... DataClient). Thos works fine, but I have no idea of how to return the Data or RemoteData class created by this command to my GUI.
Please help.
Thanks
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you bind your Connection to the RMI Registry. If so then you do a lookup in the registry.
Do a search on RMI on this forum and one should give you a link to the RMI tutorial at Sun.
Mark
 
Trevor Dunn
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really have no idea on what you are doing. Why are you using runtime.exec. And why is your security manager stopping you from starting your client. You will have to explain a lot more I think.
However, it should go like this
Start your server- bind your object
Start your client-lookup your object.
Trevor
 
rb
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answers, but nobody seems to have had this problem before . Let me describe it a bit further :
1- I need to create an instance of the Data class in order that I could work with it from my GUI.
Requirement : the user should choose the database mode at start of the application : local or remote mode. How I implemented it :
a- before the application frame, I send a window (DataMode) to allow the user to select the mode in which he wants to start. The following data are collected :
--> local mode :
+ Database Name,
--> remote mode :
+ remote object name,
+ server DNS,
+ server port,
+ Security policy file name
Suppose the following is my rmi client
public class rmiclient {
public static void main(String args[]){
new rmiclient(args);
}
public rmiclient(String parms){
String mode = args[0];
if (mode.equals("local"){
System.setSecurityManager(new RMISecurityManager());
Data mydata = new Data(args[1]);
} else if (mode.equals("network"){
System.setSecurityManager(new RMISecurityManager());
RemoteData _data = (RemoteData)Naming.lookup(args[1]);
}

}
Now, if I want to call this from the DataMode window, I can't go : new rmiclient()because this will fail, due to the policy file missing, so I have to go : Runtime.exec(java -D... rmiclient);
This works fine, and so are my client and server load individually.
The problem : this does no return to my GUI the data class instantiated !
So basically, my question is : How can I connect the GUI to the Database, using rmi and giving the user the choice as required by the assignment ?
Thanks.
 
Trevor Dunn
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi waht you are doing seems a little out of sorts. Runtime.exec may work but it does not mean it is right. Lets look at it this way.
When running in local mode you need only to instantiate an instance of Data and use this directly. There is no need for a new RMISecurityManager or policy files etc.
When in Networked mode you need to look up an instance of the object bound in your registry. Here again on the client, no RMISecurityManager, no policy file. Just a lookup.
Your RMI server on the other hand can use a policy file and a new RMI Manager, but not the client.
How you do this well I will leave that to you. I will say I used a proxy class which sent my request to either the server or local Data and it was transparent to the client.
Come to think of it All this RMISecurity manager and policy files on the client may be what is messing you up. Get rid of it and see what happens.
Trevor
 
rb
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Trevor,
i was effectivelly worried about wether the security manager had to be installed on the client or not, but could not find any clear statement on this. It is said tha if the client has to download code from another VM, then it needs to install a security manager.
I do have an interface which implementation is as :
public class DataModelImpl extends
UnicastRemoteObject implements DataModel{
Data localedata ;
RemoteDataImpl remotedata ;

public Data getloacalData( String Dbname) throws RemoteException {
localedata = new Data(Dbname);
return localedata ;
}
public RemoteDataImpl getRemoteData(Data localdata, String dbname) throws RemoteException {
remotedata = new RemoteDataImpl(new Data(dbname));
return remotedata ;
}
}
Can this be considered as a proxy ?
Thanks again
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rb,
JavaRacnh has a Naming Policy Please read and reregister with a rpoper name.
 
Steve Granton
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
That class does not conform to my understanding of what a proxy class is:
"the implementation of the Proxy pattern simply involves ceating a class that shares a common superclass or interface with a service providing class and delegates operations to instances of the service-providing class"
Under the section 'Writing Data Client' in the SCJD Application Submission document it provides:
"This implementation should include a class that implements the same public methods as the suncertify.db.Data class, although it will need different constructors..."
To my mind Sun are telling you to use a Proxy class in order to access the Data class. In my design the proxy class resolves whether to use a local or remote instance of the Data class (which I think Trevor was saying above). This information should be transparent to the client.
I hope this helps,
Steve
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic