简体   繁体   English

如何外部化插入文件SQL查询

[英]How to externalize an insert file SQL query

In my application, I want to externalize SQL query (in .properties files for example). 在我的应用程序中,我想外部化SQL查询(例如,在.properties文件中)。 But sometimes I had to insert the entire content of a text file into a CLOB column. 但是有时我不得不将文本文件的全部内容插入到CLOB列中。

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. 我确实需要将SQL逻辑与应用程序业务逻辑分离。 Any suggestions to tackle this problem. 任何解决此问题的建议。

Thanks. 谢谢。

It's not a good idea to externalize the SQL queries. 外部化SQL查询不是一个好主意。 Imagine that someone would change the .properties file to something like 假设有人会将.properties文件更改为类似

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. 此外,作为开发人员,我希望SQL查询尽可能接近源代码。 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. 例如,使用DAO模式即可轻松控制复杂性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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