Where do you put your SQL queries?

We use a combination of EJB 2.1 and JDBC to access our database.

I just had an employee who mentioned the idea of โ€‹โ€‹putting their SQL queries in a .properties file.

How and where do you put your SQL queries?

EDIT:

Did you embed it with code placed in an instance of the class?

+4
source share
5 answers

We save our SQL queries as string literals in the DAO. DAOs hide the potentially ugly SQL syntax from the rest of the application. When you delve into DAO code, having SQL queries in the context in which they will be used helps make the code more understandable.

+4
source

In DAOs , since I consider them part of my application, not a custom (modified sysadmin element) application.

+6
source

Now that I'm working, we use property files to store our SQL queries. I really like this, as I always thought it looked rather messy when in code. I really do not see it as customizable by the sys administrator, since all of them will be merged with the bank and, therefore, are invisible.

+2
source

I use Ibatis, so all requests are stored in Ibatis XML files. If there is no Ibatis, then in the DAO java code.

+1
source

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

+1
source

All Articles