1

我需要使用以下查询。

SELECT m.member_id, cardflag FROM member m, member_attribute ma WHERE m.member_number=:memberNumber AND m.ref_club_status IN ('A','S') AND m.member_id=ma.member_id

的数据类型member_id是字节数组,的数据类型cardflag是varchar。

我需要在我的代码中使用此查询,并查看 jdbctemplate 文档中的选项,queryForList 似乎是最佳选择。我一直在尝试,但无法弄清楚如何将参数传递给我的查询以及如何处理返回类型。

有人可以帮忙吗?

提前非常感谢。

4

1 回答 1

2

我的回答是

String sql = "SELECT m.member_id, searscc FROM member m, member_attribute ma " +
            "WHERE m.member_number=:memberNumber AND m.ref_club_status IN ('A','S') AND m.member_id=ma.member_id";
String memberNumber = "John Doe";                   //the argument value for the sql above
JdbcTemplate jdbcTemplate = new JdbcTemplate();     //replace this line with your own code to get JdbcTemplate instance.
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql, new Object[]{memberNumber}) ;
byte[] tempMemberIds = null;
String tempSearscc = null;
if ((rows != null) || (rows.size() > 0)) {
    for (Map<String, Object> tempRow : rows) {
        tempMemberIds = (byte[])(tempRow.get("member_id"));     //key is your search field in your sql
        tempSearscc = (String)(tempRow.get("searscc"));
        //do your own jobs
    }
} else {
    //do something else
}

希望这有用。

于 2012-08-13T09:52:12.410 回答