Java – how to use the string list in namedparameterjdbc template to get the result

Try spring JDBC I use this as a reference I'm trying to get an actor with the same name Running this code gives me the results I need:

public List<String> getActorsWithSameLastName(String lastName,NamedParameterJdbcTemplate template) {
        String query = "SELECT FIRSTNAME FROM ACTORS WHERE LASTNAME=:LASTNAME";
        Map<String,String> paramMap = new HashMap<String,String>();
        paramMap.put("LASTNAME",lastName);
        return template.queryForList(query,paramMap,String.class);
    }

I have a list of < string > last names. How do I get a list of actors with my list? Do I iterate the last name list and call getactorswithsamelastname() every time, or does spring provide an iterative method and get the results for me? Please give me some advice

Solution

Terms of use

How to use SELECT IN clause in JDBCTemplates?

List<String> lastnames= new ArrayList();

Map namedParameters = Collections.singletonMap("lastnamevalues",lastnames);

StringBuffer recordQueryString = new StringBuffer();

recordQueryString.append("select FIRSTNAME,LASTNAME from ACTORS where lastname in (:lastnamevalues) ");

List nameInvolments = this.namedparameterJdbcTemplate.query(recordQueryString.toString(),namedParameters,new MyMapper());
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>