Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 427205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:33:23+00:00 2026-05-12T19:33:23+00:00

Where should an JDBC-compliant application store its SQL statements and why? So far, I

  • 0

Where should an JDBC-compliant application store its SQL statements and why?

So far, I managed to identify these options:

  • Hardcoded in business objects
  • Embedded in SQLJ clauses
  • Encapsulate in separate classes e.g.
    Data Access Objects
  • Metadata driven (decouple the object
    schema from the data schema –
    describe the mappings between them in
    metadata)
  • External files (e.g. Properties or
    Resource files)
  • Stored Procedures

What are the “Pros” and “Cons” for each one?

Should SQL code be considered “code” or “metadata”?

Should stored procedures be used only for performance optimisation or they are a legitimate abstraction of the database structure?

Is performance a key factor the decision? What about vendor lock-in?

What is better – loose coupling or tight coupling and why?

EDITED: Thank you everyone for the answers – here is a summary:

Metadata driven i.e. Object Relational Mappings (ORM)

Pros:

  • Very abstract – DB server can be
    switched without the need to change
    the model
  • Wide-spread – practically a standard
  • Cuts down the amount of SQL needed
  • Can store SQL in resource files
  • Performance is (usually) acceptable
  • Metadata driven approach
  • (Database) vendor independence

Cons:

  • Hides SQL and true developers
    intentions
  • SQL difficult to be reviewed/changed
    by DBA
  • SQL might still be needed for odd
    cases
  • Can force usage of a proprietary
    query language e.g. HQL
  • Does not lend itself to optimisation
    (abstraction)
  • Can lack referential integrity
  • Substitutes for lack of SQL knowledge
    or lack of care to code in the DB
  • Never match native database
    performance (even if it comes close)
  • Model code is very tight coupled with
    the database model

Hardcoded/encapsulated in DAO layer

Pros:

  • SQL is kept in the objects that
    access data (encapsulation)
  • SQL is easy to write (speed of
    development)
  • SQL is easy to track down when
    changes are required
  • Simple solution (no messy
    architecture)

Cons:

  • SQL cannot be reviewed/changed by DBA
  • SQL is likely to become DB-specific
  • SQL can become hard to maintain

Stored Procedures

Pros:

  • SQL kept in the database (close to
    data)
  • SQL is parsed, compiled and optimised
    by the DBMS
  • SQL is easy for DBA to review/change
  • Reduces network traffic
  • Increased security

Cons:

  • SQL is tied to the database (vendor
    lock-in)
  • SQL code is harder to maintain

External files (e.g. Properties or Resource files)

Pros

  • SQL can be changed without a need to
    rebuild the application
  • Decouples the SQL logic from the
    application business logic
  • Central repository of all SQL
    statements – easier to maintain
  • Easier to understand

Cons:

  • SQL code can become un-maintainable
  • Harder to check the SQL code for
    (syntax) errors

Embedded in SQLJ clauses

Pros:

  • Better syntax checking

Cons:

  • Ties too closely to Java
  • Lower performance than JDBC
  • Lack of dynamic queries
  • Not so popular
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:33:24+00:00Added an answer on May 12, 2026 at 7:33 pm

    Usually, the more the application grows in terms of size and/or reusability, the more the need is to externalize/abstractize the SQL statements.

    Hardcoded (as static final constants) is the first step.
    Stored in a file (properties/xml file) is the next step.
    Metadata driven (as done by an ORM like Hibernate/JPA) is the last step.

    Hardcoded has the disadvantage that your code is likely to become DB-specific and that you need to rewrite/rebuild/redistribute on every change. Advantage is that you have it in 1 place.

    Stored in a file has the disadvantage that it can become unmaintainable when the application grows. Advantage is that you don’t need to rewrite/rebuild the app, unless you need to add an extra DAO method.

    Metadata driven has the disadvantage that your model code is very tight coupled with the database model. For every change in the database model you’ll need to rewrite/rebuild/redistribute code. Advantage is that it is very abstract and that you can easily switch from DB server without the need to change your model (but ask yourself now: how often would a company switch from DB server? likely at least only once per 3 years, isn’t it?).

    I won’t call stored procedures a “good” solution for this. They have an entirely different purpose. Even though, your code would be dependent on the DB / configuration used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[1] In JDBC, why should we first load drivers using Class.forName(some driver name). Why
Should developers avoid using continue in C# or its equivalent in other languages to
Should libraries that the application relies on be stored in source control? One part
I am trying to make my java application more standards compliant and one of
When using a PreparedStatement in JDBC, should I close the PreparedStatement first or the
I downloaded microsfot's jdbc driver, and I am not sure what the connection.url should
I'm using persistence API and want to load jdbc URL from web.xml. URL should
I have the following dependency in my pom.xml <dependency> <groupId>javax.sql</groupId> <artifactId>jdbc-stdext</artifactId> <version>2.0</version> <scope>system</scope> <systemPath>${java.home}/lib/rt.jar</systemPath>
I'm trying to select a JDBC driver for an application I'm building and I've
I am planning to execute Oracle PL\SQL blocks via JDBC (can't test it yet,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.