wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Enabling non-programmers to change the output of my code ? 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 » Java » Beginning Java
Bookmark "Enabling non-programmers to change the output of my code ?" Watch "Enabling non-programmers to change the output of my code ?" New topic
Author

Enabling non-programmers to change the output of my code ?

justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
Hi !

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.





Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18715
    
    8

A generalized database query application? Frankly, the simplest thing for all concerned would be to acquire one which already exists and give that to them.
justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
Paul Clapham wrote:A generalized database query application? Frankly, the simplest thing for all concerned would be to acquire one which already exists and give that to them.


I was hoping that you could tell me if a config file may be used ? If yes, then how do i go about creating it and using it in an eclipse project.
Will XML be okay for this purpose ?

Btw, this is not really a real project. Its just my own thing and I wanted to experiment a little.
Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 174
    
    5

A Java properties file sounds like it could be useful to you. You can write them in either key=value pairs or in XML.
http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html

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
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8060
    
  22

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).

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11448
    
  16

you would probably also want to limit those power user's ability to do UPDATE, DROP TABLE or other destructive stuff.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8060
    
  22

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.

Winston
justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
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):
<task>
<table>
<table name>Customers</table name>
<column>Name</column>
<column>Address</column>
</table>
</task>

My code will now pick the table and perform a query -
select name, address
from Customers

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.

Extra stuff:
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 ?



justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
This is what I got so far.
stack overflow - apache commons - configuration
Looks like its good - apache stuff.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42374
    
  64
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.


Ping & DNS - my free Android networking tools app
 
jQuery in Action, 2nd edition
 
subject: Enabling non-programmers to change the output of my code ?