Example usage for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate queryForObject

List of usage examples for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate queryForObject

Introduction

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

Prototype

@Override
    @Nullable
    public <T> T queryForObject(String sql, Map<String, ?> paramMap, Class<T> requiredType)
            throws DataAccessException 

Source Link

Usage

From source file:ch.digitalfondue.npjt.QueryType.java

private static Object handleSingleObject(String template, NamedParameterJdbcTemplate jdbc,
        SqlParameterSource parameters, Collection<ColumnMapperFactory> columnMapperFactories, Class<Object> c,
        HasRowmapper r) {//from   w  w  w.ja  va  2 s .co  m
    if (r.present) {
        return jdbc.queryForObject(template, parameters, r.rowMapper);
    } else {
        RowMapper<Object> rowMapper = matchToOutput(columnMapperFactories, c);
        if (rowMapper != null) {
            return jdbc.queryForObject(template, parameters, rowMapper);
        } else {
            return jdbc.queryForObject(template, parameters, c);
        }

    }
}

From source file:cherry.sqlapp.service.sqltool.exec.ExecQueryServiceImpl.java

private long count(DataSource dataSource, String sql, Map<String, ?> paramMap) {
    NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource);
    return template.queryForObject(sql, paramMap, Long.class);
}

From source file:cherry.foundation.etl.LoaderImplTest.java

private String getAddressByName(String name) {
    NamedParameterJdbcTemplate template = getTemplate();
    Map<String, String> paramMap = new HashMap<>();
    paramMap.put("name", name);
    return template.queryForObject("SELECT address FROM etl_extr_ldr_test WHERE name = :name", paramMap,
            String.class);
}

From source file:org.tradex.jdbc.JDBCHelper.java

/**
 * Issues a query for an Object/*  w  ww.jav  a2 s .  c o m*/
 * @param <T> The expected return type
 * @param sql The SQL
 * @param clazz The expected return type
 * @param binds The bind values
 * @return an Object
 */
public <T> T templateQueryForObject(CharSequence sql, Class<T> clazz, Object... binds) {
    NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(ds);
    return template.queryForObject(sql.toString(), getBinds(sql.toString().trim().toUpperCase(), binds), clazz);
}

From source file:com.joliciel.jochre.boundaries.BoundaryDaoJdbc.java

@Override
public Split loadSplit(int splitId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_SPLIT + " FROM ocr_split WHERE split_id=:split_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("split_id", splitId);

    LOG.debug(sql);//  w w  w  . j a  va 2 s  . c  om
    logParameters(paramSource);
    Split split = null;
    try {
        split = (Split) jt.queryForObject(sql, paramSource, new SplitMapper(this.getBoundaryServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return split;
}

From source file:com.joliciel.jochre.security.SecurityDaoJdbc.java

@Override
public User loadUser(int userId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_USER + " FROM ocr_user WHERE user_id=:user_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("user_id", userId);

    LOG.info(sql);/* www .  ja va2s  .c  o  m*/
    logParameters(paramSource);
    User user = null;
    try {
        user = (User) jt.queryForObject(sql, paramSource, new UserMapper(this.getSecurityServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return user;
}

From source file:com.joliciel.jochre.security.SecurityDaoJdbc.java

@Override
public User findUser(String username) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_USER + " FROM ocr_user WHERE user_username=:user_username";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("user_username", username);

    LOG.info(sql);/*from w  w  w .j a  va 2  s . co  m*/
    logParameters(paramSource);
    User user = null;
    try {
        user = (User) jt.queryForObject(sql, paramSource, new UserMapper(this.getSecurityServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return user;
}

From source file:com.joliciel.jochre.security.SecurityDaoJdbc.java

@Override
public Parameters loadParameters(int parametersId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_PARAM + " FROM ocr_param WHERE param_id=:param_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("param_id", parametersId);

    LOG.info(sql);/*from   ww  w .ja va2 s . c  o m*/
    logParameters(paramSource);
    Parameters parameters = null;
    try {
        parameters = (Parameters) jt.queryForObject(sql, paramSource,
                new ParametersMapper(this.getSecurityServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return parameters;
}

From source file:com.joliciel.jochre.doc.DocumentDaoJdbc.java

@Override
public Author loadAuthor(int authorId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_AUTHOR + " FROM ocr_author WHERE author_id=:author_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("author_id", authorId);

    LOG.info(sql);// w w w.j a v a  2s.com
    logParameters(paramSource);
    Author author = null;
    try {
        author = (Author) jt.queryForObject(sql, paramSource,
                new AuthorMapper(this.getDocumentServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return author;
}

From source file:com.joliciel.jochre.doc.DocumentDaoJdbc.java

@Override
public JochrePage loadJochrePage(int jochrePageId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_PAGE + " FROM ocr_page WHERE page_id=:page_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("page_id", jochrePageId);

    LOG.info(sql);//from   ww w .j  ava 2  s.  c om
    logParameters(paramSource);
    JochrePage jochrePage = null;
    try {
        jochrePage = (JochrePage) jt.queryForObject(sql, paramSource,
                new JochrePageMapper(this.getDocumentServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return jochrePage;
}