我需要使用以下查询。
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似乎是最佳选择。我一直在尝试,但无法知道如何将参数传递给我的查询以及如何处理返回类型。
有人可以帮忙吗?
提前多多感谢。
答案 0 :(得分: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
}
希望这有用。