• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confused about location of database in local and remote mode

 
Charu Krishnan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DataClient is the client program
--------------------------------cha
public class DataClient {
RemoteData myData;
public DataClient(String connection) throws RemoteException, Exception {
System.out.println("Starting DBClient(String) constructor");
if (connection.equals("local"))
myData = new DataConnectImpl(db.db");
else
// System.setSecurityManager(new RMISecurityManager());
myData = (RemoteData) Naming.lookup("rmi://"+ "127.0.0.1:1099" + "/dataserver");
}
}

class Remote Data is the Remote Interface implementing all the Data Class Methods with Remote and DataBase Exception
class DataConnectImp is the Remote object ie middle tier and has all methods of the Data Class
Now I have a class FBNModel that basically defines the GUI . To this I want to pass the package variable mydata(declared as a package variable in DataClient), so that it is transperant wether I am using the local or network mode. But I get an error �Variable myData is not declared in FBNModel� (even though I declared it with package scope in myData). What am I doing wrong here . How have others worked around this.
The other thought was to declare myData in FBNModel as follows.
MyData = new Data(db.db). But in doing this does it not defeat the purpose of what I am trying to achieve in DataClient. In declaring myData in FBNModel will the Network Mode not wrongly get a copy of the database on the c drive, is this OK?. Just very confused.

public class FBNModel extends JFrame {
�variable declaration
public FBNModel() {
super("Fly By Night Reservation System");
try {
schema = myData.getFieldInfo();
recordCount = myData.getRecordCount();
columnCount = myData.getFieldInfo().length;
}
}
}
Thanks
Charu
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do not have any reference in your GUI class to myData. Irregardless that it is in the same package. same package really deals with classes, not instances. Meaning there still needs to be a reference passed to the GUI class so that it knows the myData instance.
You could pass myData to the constructor of the GUI class, or you can have the GUI class instantiate the "myData" class. I forgot the actual class name that you gave it, that's why I put myData in quotes. I think of myData as an instance of your class.

Hope that helps you
Mark
 
Charu Krishnan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark and friends,
Had a queston about creating the instance of myData in my GUI. I will d0 it with code like
try
{
myData = new Data("c:/javadevback/scjd/starting/suncertify/db/db.db");
}
So here is my doubt and this may seem basic to some
In my Data Client class my code says:
if (connection.equals("local"))
myData = new DataConnectImpl("c:/javadevback/scjd/starting/suncertify/db/db.db");
else
System.setSecurityManager(new RMISecurityManager());
myData = (RemoteData) Naming.lookup ("rmi://"+ "127.0.0.1:1099" + "/dataserver");
}
This way I can use the remote or local version and it is transperant to the user. My question is that what will creating another insatnce of database in my GUI do. When I do the locking will creating another instance create a lock on the second instance , or physically is there just one version of the database. Just confused. Also in the remote version is it Ok to do this. Can anyone tell me if what I am doing in the DataClient class and GUI is ok.
Thanks
Charu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic