我需要查询数据库,但该查询的参数值需要来自文件,这是代码...
BufferedReader reader = new BufferedReader(new FileReader("C:/DBMigrations/empIDs.txt"));
String line = null;
String query = "select name, address from Employee where id in (";
while ((line = reader.readLine()) != null) {
// the value of line needs to be plugged into query inside the in clause
}
我正在使用Spring的SimpleJdbcTemplate。
在此先感谢您的帮助。
您可以简单地使用一种方法来从文件中生成一个串联的id的标记。
String query = "select name, address from Employee where id in ("+geneateEmployeeIds()+")";
private String geneateEmployeeIds(){
// read your file here and convert it to string<br>
// do id concatenation here
return ids;
}
您可以了解如何在此处获取文件的字符串内容
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句