Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL in properties file

 
Eric Gero
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks,
Eric
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eric Gero
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Eric
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Herman
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic