develog

callback test 본문

Dev/Java

callback test

냐옴 2012. 8. 6. 19:48

interface JdbcTemplateHandler {

public Object mapRow(String param, JdbcTemplateHandler handler);

}


class JdbcTemplate implements JdbcTemplateHandler {

public Object queryForObject(String param, JdbcTemplateHandler handler) {

System.out.println("query executing...");

try {

Thread.sleep(3000);

} catch (InterruptedException e) {

e.printStackTrace();

}

return mapRow(param, handler);

}

public Object mapRow(String param, JdbcTemplateHandler handler) {

return handler.mapRow(param, handler);

}

}


public class CallBackTest {

public static void main(String[] args) {

JdbcTemplate jdbcTemplate = new JdbcTemplate();

String retVal = (String)jdbcTemplate.queryForObject("123ABC", new JdbcTemplateHandler() {

public Object mapRow(String param, JdbcTemplateHandler handler) {

return "RETURN VALUE, " + param;

}

});

System.out.println("retVal : " + retVal);

}

}


'Dev > Java' 카테고리의 다른 글

[Tomcat] jsp cache clear  (0) 2012.10.08
timestamp 출력  (0) 2012.09.21
cmd 에서 jar 만들기  (0) 2012.06.13
줄바꿈 문자  (0) 2012.06.13
java file copy test  (0) 2012.05.24
Comments