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
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.
Comments
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
- 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