Spring JdbcTemplate – Single/Multiple Column Result

Single Column Result

Find The Number of Menu Items
DAO

public Long findCount() {
Long menuCount = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM menu", Long.class);
return menuCount;
}

TestDAO

MenuDAO dao = new MenuDAO();
Long count = dao.findCount();
System.out.println(count);

Multiple Column Result

List of Menu Names
DAO

public List<String> findMenuNames() {
List<String> menuNameList = jdbcTemplate.queryForList("SELECT name FROM menu", String.class);
return menuNameList;
}

TestDAO

List<String> menuNames = dao.findMenuNames();
for (String menuName : menuNames) {
	System.out.println(menuName);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s