0

I have a small app in which a user uploads a file which carries bunch of id's. I read the file and store all those id's in a list. Now for each id I need to query database so that I could select some other other info. My question is that how to incorporate those id's as part of select statement?

Currently I am querying manually just by typing the id and I want to know how to use getter() as part of query?

Method to select from database

public List<NYProgramTO> getLatestNYData() throws Exception {
    String query = "SELECT REQ_XMl, SESSIONID, EXPIRATION_DATE, QUOTE_DATE, POLICY_EFFECTIVE_DATE, TARGET_CREATED, RATING_TRANSACTION_ID, SOURCE_LASTMODIFIED, PREM_WHEN_RERATED FROM dbo.XML_SESSIONS with (nolock) WHERE XML_SESSIONS.LOB = 'PersonalAuto' AND XML_SESSIONS.RATING_STATE = 'NY' AND XML_SESSIONS.ID IN ('72834052') ORDER BY XML_SESSIONS.SOURCE_LASTMODIFIED DESC";

    return this.sourceJdbcTemplate.query(query, (rs, rowNum) -> {
        NYProgramTO to = new NYProgramTO();
        to.setRequestXML(rs.getString("REQ_XML"));
        to.setExpirationDate(rs.getDate("EXPIRATION_DATE"));
        return to;
    });
}

Thanks

David
  • 257
  • 1
  • 8
  • 24
  • 1
    [This](https://stackoverflow.com/questions/17842211/how-to-use-an-arraylist-as-a-prepared-statement-parameter) might be a good place to start. – Andrew S Mar 21 '18 at 18:36

1 Answers1

0

You can use MapSqlParameterSource to map the parameter.

public void selectExample(Car car){

   String query = "select * from car where id_car = :id and color = :color";

   this.sourceJdbcTemplate.query(query, new MapSqlParameterSource("id", car.getId()).addValue("color", car.getColor()), new CarRowMapper());
}
cvdr
  • 939
  • 1
  • 11
  • 18