Reputation: 168
I need to use the following query.
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
The datatype of member_id
is byte array, and that of cardflag
is varchar.
I need to use this query in my code, and looking at the options in jdbctemplate documentation, queryForList seems to be the best choice. I have been trying, but couldnt make out much as to how to pass the parameter to my query and also as to how to handle the return type.
Can anyone please help?
Thanks a lot in advance.
Upvotes: 1
Views: 17503
Reputation: 373
My answer is
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
}
Hope this useful.
Upvotes: 2