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.
Eric, 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.
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.
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.
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.