简体   繁体   中英

How to externalize an insert file SQL query

In my application, I want to externalize SQL query (in .properties files for example). But sometimes I had to insert the entire content of a text file into a CLOB column.

This is the code I use now:

 String requete = "the content of the file in xml";
 PreparedStatement prepareStatement = con.prepareStatement("INSERT INTO \"TABLE\".\"_XML\" (ID, BLOC_XML) VALUES ('1',?)");
 prepareStatement.setCharacterStream(1, new StringReader(requete), requete.length());

I really need to decouple the SQL logic from the application business logic. Any suggestions to tackle this problem.

Thanks.

It's not a good idea to externalize the SQL queries. Imagine that someone would change the .properties file to something like

drop table really_important_stuff;

Furthermore, as a developer I would prefer to have the SQL queries as close to the source code as possible. So that I do not need to look them up in some other resource.

It's simple to gain control of the complexity using DAO pattern for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM