0

I need to query the DB but the parameter values from that query need to come from a file, here is the code...

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
    }

I am using Spring's SimpleJdbcTemplate.

Thanks in advance for any help.

AbuMariam
  • 3,282
  • 13
  • 49
  • 82
  • Are you going to create single sql corresponding to single row in file ?? Mean you will have multiple query – Kick Feb 15 '14 at 19:25

1 Answers1

1

You could simply have one method which generates a token of concatenated ids from file.

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;
}

You can have an idea of how you can get the string content of file here

Community
  • 1
  • 1
Jama A.
  • 15,680
  • 10
  • 55
  • 88