• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database path + Database name ?

 
Pete Palmer
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pete Palmer
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello Roberto,

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

Pete.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Axel Leucht
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to add that I check that the file exists and is writeable as well.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic