• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SQL queries

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

How to decide that it is good to keep all the SQL queries in the DAO class itself or keep it in the database or some text file.

Thanks.
 
Ranch Hand
Posts: 31
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sahil,

It depends what persistence framework you will use.

Examples:
- Hibernate, you can put the simple queries at NamedQueryes in Pojos...
- Ibatis, you can put the queries in xml files...
- DataBase you will need to use StoredProcedures or Function to use the queries...
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sometimes I keep my queries in a Java Constants File as static final Strings. But may be this would cause JVM memory issues.

Cheers
Sid
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sidd Kulk wrote:Sometimes I keep my queries in a Java Constants File as static final Strings. But may be this would cause JVM memory issues.


 
Sidd Kulk
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sagar,

Like you keep your query strings in properties file and then fetch them at runtime, you can create a Constants class, and declare public static final Strings.

e.g.



My DAO class would be:


In case of web applications, if there are too many queries, this would cause memory issues in JVM as the queries would remain loaded in memory all the time..

Hope this explains

Cheers!
Sid
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I totally agree with your explanation and code, but I don't think declaring static string instance will cause any memory problems, after all they are not heavy resources like, IO streams or DB connections. And we know there is SCP (String Constant Pool), which takes care that there is only one such string exits in JVM memory, that means no duplication and I thought that ain't be the problem to memory
 
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic