Example usage for org.springframework.jdbc.core JdbcTemplate queryForObject

List of usage examples for org.springframework.jdbc.core JdbcTemplate queryForObject

Introduction

In this page you can find the example usage for org.springframework.jdbc.core JdbcTemplate queryForObject.

Prototype

@Override
    public <T> T queryForObject(String sql, Class<T> requiredType, @Nullable Object... args)
            throws DataAccessException 

Source Link

Usage

From source file:wherehows.dao.table.DatasetsDao.java

/**
 * get WhereHows dataset id by dataset URN
 * @param jdbcTemplate JdbcTemplate//w  w w.  ja  v a 2  s  .  c  om
 * @param urn String
 * @return dataset ID, if not found, return -1
 */
public int getDatasetIdByUrn(JdbcTemplate jdbcTemplate, String urn) {
    try {
        return jdbcTemplate.queryForObject(GET_DATASET_ID_BY_URN, Integer.class, urn);
    } catch (EmptyResultDataAccessException e) {
        log.debug("Can not find dataset id for urn: " + urn + " : " + e.toString());
    }
    return -1;
}