This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Database path + Database name ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Database path + Database name ?" Watch "Database path + Database name ?" New topic
Author

Database path + Database name ?

Pete Palmer
Ranch Hand

Joined: Oct 21, 2008
Posts: 92
Hi,

Just wanted the correct interpretation of my requirement :-

the program must allow the user to specify the location of the database


I have interpreted this as providing the user with the facility to specify the path to the database BUT not the database file name and the database file name to use, is as per the file provided by Sun. In my case, "db-2x2".

Or should it be interpreted as the user should be able to specify the path to the database file AND also the name of the database file. "C:\suncertify\database\db_another"

Thank you.

Pete
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

Partner, this is for the network approach, right? Here's what I did: when my application starts in server mode, I display a dialog, where the user inserts the database location and the port number in which the server will run. Both are JTextFields, and the port number allows only numbers. Now, in the database location, the user provides the entire path to the database file. So, for instance, if the database file is in C:\Pete\SCJD\db-2x2.db, then I expect the user to enter C:\Pete\SCJD\db-2x2.db. And before using the Data class, I verify if the path provided is valid (if (!new File(dbPath).exists())); if it isn't, I throw InvalidDatabaseException.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Pete Palmer
Ranch Hand

Joined: Oct 21, 2008
Posts: 92

Hello Roberto,

Thanks for the clarification and detail of how to handle the scenario.

Pete.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5444
    
  13

Roberto Perillo wrote:Partner, this is for the network approach, right?


And what with the standalone application (without network)? Should the user not indicate where the db-file is too or is your program supposed to guess its location?


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

And what with the standalone application (without network)? Should the user not indicate where the db-file is too or is your program supposed to guess its location?


No, no... I treat both cases the same way (the user also has to provide in a JTextField the entire database path)
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5444
    
  13

ok then, i already thought i had to implement some artificial intelligence to guess the database file name
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11490
    
  95

Roberto Perillo wrote:the user also has to provide in a JTextField the entire database path

Have you considered a javax.swing.JFileChooser to allow the user to browse to the location of your file rather than just a text box?

(And yes, this is rhetorical, given you have passed )

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Axel Leucht
Greenhorn

Joined: Jan 19, 2009
Posts: 21
I want to add that I check that the file exists and is writeable as well.


Regards

SCJP, SCJD
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

Andrew Monkhouse wrote:Have you considered a javax.swing.JFileChooser to allow the user to browse to the location of your file rather than just a text box?


Hey, my good buddy Andrew!
For this project, I tried to keep things as simple as possible, you know... since it wasn't required, I just went with the JTextField.

Axel Leucht wrote:I want to add that I check that the file exists and is writeable as well.


Partner, this isn't really necessary...
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2561
    
    9

This thread of mine earlier can be some help.

JTextField vs JFileChooser? Depends JFileChooser will not need to file existence, wrong magic cookie value etc and the only real disadvantage is the file must on the same machine that you are running the app.

The JTextField would indeed need to check file existence, cookie value etc and the major advantage is the database file can practically be on another computer.

For example: CompA is your server, you can specify a file on CompB if you really like (within the LAN of course).

For me I used a JTextField and did all those checking BEFORE saving the configuration.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database path + Database name ?