I have a Java project which will include a number of large SQL statements for querying the database. My question is: where should I store them?
I'm fairly sure I want each statement its own text file managed by source code control. As Java doesn't support multi-line strings I can't easily put the SQL in my .java
files and I don't think I'd want to anyway. At build time I can put these text files in JAR and get the contents with ClassLoader.getResourceAsStream()
.
So my problem becomes in which directories should I put these files and what should I call them. Ideally I'd like people to tell from the .sql
file which Java class uses it. What I definitely don't want is a single directory full of lots of files called things like report1.sql
and report3.sql
and so on.
My inclination is to put them in the package directory with all the .java
files but I have a colleague who doesn't like having anything other than .java
files in this tree. So this leads to alternative of a separate directory structure which mirrors the Java packages but this seems like an unnecessary overhead.
So I would be interested to hear what you do with your SQL files.
We're using Netbeans 6.5 in case that will affect your answers.
(This question is similar but sadly the answers are very C# specific, which is good for that question but bad for me.)