File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes SQL in properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL in properties file" Watch "SQL in properties file" New topic

SQL in properties file

Eric Gero
Ranch Hand

Joined: Jul 20, 2005
Posts: 73
Does anyone have experience with putting SQL statements in properties files? Is it a good idea, are there things I should or shouldn't do? My app is an executable jar that runs on a schedule once a day, so I am not worried about any extra time it may take to load the SQL. I would like to hear your ideas.

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33107

It's not inherently good or bad. The typical advantage of putting things in property files is that you can change them without recompiling the code. Not sure how often that happens in a jar though.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

One downside of properties files is the encoding needs to be ISO Latin-I, which is fine for the SQL, but might not be fine for any parameter values you need to include. Of course this is not an issue if you know you will never have characters not supported by thge ISO Latin-I character set, but it is something to consider.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Eric Gero
Ranch Hand

Joined: Jul 20, 2005
Posts: 73
Thanks for the tips, I had not considered any encoding issues. The only reason I was thinking of putting it in a properties file, is because the SQL is fairly long, and is making the code more difficult to read. Plus I was thinking that as long as I didn't change the fields returned, I could change the SQL without recompiling.

Herman Schelti
Ranch Hand

Joined: Jul 17, 2006
Posts: 387
hi Eric,

I usually/nearly always put the SQL that I use in web-applications in an XML-file:
-I test the SQL first, then copy/paste it into the XML-file
-Easier to read (especially for people who know SQL but don't know Java)

The webapplication parses the xml-file only once (at start-up), and stores it in memory as key/value pairs.

I agree. Here's the link:
subject: SQL in properties file
It's not a secret anymore!