• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not to hard code database location

 
Qusay Jaafar
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
what I did is the following:
1. server administrator will enter the port from the command promp
2. database location determined by using:
String dir = System.getProperty("user.dir");
dir.concat("/suncertify/db/db.db");
3. in case of network connection, the user will enter the computer name he wants to connects to (of course, where the database locate).
later, I will let the user to use JFileChooser to find the database location or by typing the location into a JTextField.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Qusay,

1. server administrator will enter the port from the command promp

If your assignment is the old one, I think it is ok as it has no limitation on running the application.
However, if your assignment is the new one, the only command that you can used are:
1. java -jar runme.jar (for client network mode)
2. java -jar runme.jar alone (for client standalone mode)
3. java -jar runme.jar server (for starting up the server)
Thus, any info that must be pass to the programs, what I did, can only be do so by capturing them via a GUI.

2. database location determined by using:
String dir = System.getProperty("user.dir");
dir.concat("/suncertify/db/db.db");

This sounds reasonable, but for a bit more flexiability, I create 1 more button "Select" in the configuration GUI, for the client to choose his own db file. And my program checks the "magic cookie" to see whether the chosen file is a valid one.
Nick.
 
Qusay Jaafar
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply,
It is the old assignment (FBN).

This is what I meant by using JFileChooser, but what about the validation of the file, shall I do checking on the name of the database file which is "db.db" or there is something else.
don't you think even if you choose wrong file, an exception will be thrown throw the processing of the database?
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Qusay,
I wouldn't check the file name, but the magic cookie value as Nicholas suggests.
don't you think even if you choose wrong file, an exception will be thrown throw the processing of the database?

Possibly. But it could lead your app to corrupt a bad file. The magic cookie is there to *identify* a given file as a db file. Why not implementing that little security feature?
Regards,
Phil.
 
Jacques Bosch
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So my magic cookie is 512 in my db file, or what ever.
If I do a check for it, how do I know they won't run my app against another db file with a different magic cookie value?
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jacques,
If I do a check for it, how do I know they won't run my app against another db file with a different magic cookie value?

From the magic cookie's definition in the instructions: "4 byte numeric, magic cookie value. Identifies this as a data file". I think that from that "a", we can deduce that other possible data files would have the same magic cookie value.
Best,
Phil.
[ January 31, 2004: Message edited by: Philippe Maquet ]
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As Phil suggests, I have defined my own exception: InvalidDatabaseFileException, and I define a constant: MAGIC_COOKIE.
And the program looks like:

Hope this help.
Nick.
 
Jacques Bosch
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Makes sence. Thanx
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic