mahesh
mahesh

Reputation: 1633

how to write spring jdbc batch select sql statment

need to pass two parameters from List . need read each element ABCDTO from List and then pass to select statment where a=abcDTO.a and b= abcDTO.b like that.

please let me know which method of jdbc template to be used.

Upvotes: 1

Views: 3560

Answers (1)

Prancer
Prancer

Reputation: 3546

I am not quite sure what you are asking for. It sounds to me like you want to know how to write the SQL statement for your jdbcTemplate to use.... or maybe you are asking for how to iterate through a resultSet? Or, maybe which method will get you a resultSet as a List?

I'd love to help but please clarify your question. There are numerous posts out there that explain (very well) each of these topics. I would first start learning by using springs tuts and the API.

Also, if you want to make things a little easier for your co-workers or self in the future consider using JdbcDaoTemplate class or NamedParameterJdbcTemplate. These help to simplify your code and makes maintenance easier in the long run (imo).

Here is an example of using JdbcTemplate, and the SQL to go with it:

private static final String  SQL_RETRIEVE = "SELECT FATHER, MOTHER, SON " +
    "FROM DATABASENAME.TABLENAME WHERE FATHER = ? AND MOTHER = ?";

@Autowired
private JdbcTemplate jdbcTemplate;

public Family retrieve(String pFather, String pMother) {
    return this.jdbcTemplate.queryForObject(SQL_RETRIEVE, Object[] {pFather, pMother},
        new RowMapper<Family>() {
            @Override
            public Family mapRow(ResultSet pResultSet, int pRowNumber) throws SQLException {
                final Family family = new Family();
                family.setFather(pFather);
                family.setMother(pMother);
                family.setSon(pResultSet.getString("SON"));

                return family;
                }
        });
}

Upvotes: 2

Related Questions