tags:

views:

239

answers:

5

We are using a mix of EJB 2.1 and JDBC to access our Database.

I just had a co-worker mention the idea to put his SQL Queries into a .properties file.

How and Where do you put your SQL Queries?

EDIT:

Do you inline it with the code, put into the class instantiation?

+6  A: 

In DAOs since I consider them part of my application and not a configurable (changeable by a sysadmin) element of the application.

cherouvim
+1  A: 

I use Ibatis so all the queries reside in Ibatis XML files. If not Ibatis then in DAO java code.

Bhushan
+1  A: 

I usually add queries as static strings in the DAO implementation that uses them.

duffymo
A: 

Where I work now we use properties files to store our SQL queries. I quite like it since I've always thought it looks rather messy when in the code. I dont really see it as configurable by a sys admin since they will all be bundled with the jar and hence invisible.

willcodejavaforfood
main reason i disagree with this form is because you end up separating everything. If for any reason i require to read the code i end up having to jump over to huge property file to find it.
Nuno Furtado
But on the other hand it makes the code more readable and at the same time the SQL more readable by having them in separate files. Probably a matter of personal preference :)
willcodejavaforfood
+3  A: 

We store our SQL queries as string literals in DAOs. The DAOs hide the potentially ugly SQL syntax from the rest of the application. When you do dig down into the DAO code, having the SQL queries in the context in which they will be used helps make code easier to understand.

Andy Holt