3

We are developing an application which uses JDBC API. We deal with lot of queries for various use cases. Any idea on how to isolate these SQL queries out of the code? Is there any pattern or configuration API would help to manage these queries?

5 Answers 5

1

I'm not quite sure what you're asking, but perhaps setting up some stored procedures would provide the layer of abstraction you desire...

You could set up stored procedures for each usage case, and then the queries in your code would consist simply of calling the various procedures.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use the MyBatis SQL Mapper for this. You segregate your SQL statements into XML files. It's very clean and very intuitive if you are familiar with SQL.

Comments

0

Use a config/resource file and read the query string from it? A HashTable would be another option as well.

Comments

0

You can try to place your queries into separate files as is and then put files' names into any configuration file.

Comments

0
  • Use http://www.mybatis.org/ to externalise the queries into XML files
  • Ensure that classes that access the database only do this, and not other logic

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.