我需要查询数据库,但该查询的参数值需要来自一个文件,这里是代码......
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。
提前感谢您的帮助。
答案 0 :(得分:1)
您可以使用一种方法从文件中生成连锁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;
}
您可以了解如何获取文件here
的字符串内容