I made some code to extract data from a database. The users(non-programmers) of
my program might want to change the tables or columns from which they want to extract data.
I want to make this process as easy and smooth as possible for them.
Can you suggest how I can do that ? I was thinking of some kind of config file
that could be created for this purpose. My program would pick up the requirements from
the config file. Users can change the config file or create multiple config files and choose
which one they want to see.
As of now, I have hard-coded everything into my program. Additionally, I do not want the
users to run some code and enter the values every time they want to extract data.
I need your help to make this happen.
Thanks in advance.
I don't see how the properties file is related to eclipse - if you want it configurable, it's a value specified at runtime. I've always seen the properties files named as xxx.properties (not sure if that's a convention?). In a GUI application you'd probably want to let the user click a button to pick the config file and in a command line app you could probably specify it as an argument to the program. Either way it's just a text file formatted as described in the documentation.
You are, of course trusting your users to ensure that the configuration is valid.
Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
justin smythhe wrote:I was hoping that you could tell me if a config file may be used ?
Like Tina, I'm not sure that a properties file is what you want (except possibly to specify fairly static stuff).
Seems to me that the most useful thing for a user would be some sort of "query builder" as Paul suggested; and Swing has all sorts of gadgets that might be useful (eg, drop-down lists for choosing a table name or checkboxes for fields to be included).
I reckon that the main thing you're going to run into is that you'll need to do a fairly thorough lexical analysis of an SQL SELECT statement. My suggestion would be to (at least initially) come up with something that covers the basics, and possibly an editing window for your "power users" (ie, those that know a bit of SQL). Then, just display the results in a grid, the way most desktop db's do.
One thing I would warn you: queries generated by those dangerous bods that have "a bit of knowledge" can bring your database to a standstill (UNIONs are particularly nasty for this), so I'd be careful who you give 'full rein' of your utility to. Either that or reject queries that are likely to tax the system heavily (EXPLAIN PLAN may help there, but I've never tried to parse the results so I can't advise).
Isn't it funny how there's always time and money enough to do it WRONG?
fred rosenberger wrote:you would probably also want to limit those power user's ability to do UPDATE, DROP TABLE or other destructive stuff.
Nah. You can always blame that stuff on the DBA.
Joined: Jul 06, 2012
I am very sorry that I forgot to mention this- My code allows only data access and NOT modification.
Can I use a simple text based file instead - like xml or json ? Are there any other ways ?
For example my file can look like this (not real xml):
<table name>Customers</table name>
My code will now pick the table and perform a query -
select name, address
If the user decides that he wants to see the age of a customer also,
then he can easily add "<column>Age</column>" to the above file.
Security: Lets say the user wants to access the database by putting the password in a separate "config file",
instead of typing it into some program. Is this method of access okay ?
XML is tricky to get right for non-tech audiences; I would advise against that. You might consider a properties files, or -seeing that this is apparently a desktop app- a Swing GUI for the various input parameters.