@Repository public class DatabaseDAO { @Autowired private SimpleJdbcTemplate jdbcTemplate; public List<String> getAllRecords() { return jdbcTemplate.queryForObject("select record from my_table", List.class); } }
public Spitter getSpitterById(long id) { return jdbcTemplate.queryForObject( SQL_SELECT_SPITTER_BY_ID, new ParameterizedRowMapper<Spitter>() { public Spitter mapRow(ResultSet rs, int rowNum) throws SQLException { Spitter spitter = new Spitter(); spitter.setId(rs.getLong(1)); spitter.setUsername(rs.getString(2)); spitter.setPassword(rs.getString(3)); spitter.setFullName(rs.getString(4)); return spitter; } }, id ); }
@Deprecated public <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, SqlParameterSource args) throws DataAccessException { return queryForObject(sql, (RowMapper<T>) rm, args); }
@Deprecated public <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Map<String, ?> args) throws DataAccessException { return queryForObject(sql, (RowMapper<T>) rm, args); }
@Deprecated public <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Object... args) throws DataAccessException { return queryForObject(sql, (RowMapper<T>) rm, args); }
public Spitter getSpitterById(long id) { Map<String, Object> args = new HashMap<String, Object>(); args.put("id", id); jdbcTemplate.queryForObject(SQL_SELECT_SPITTER_BY_ID, new ParameterizedRowMapper<Spitter>() { public Spitter mapRow(ResultSet rs, int rowNum) throws SQLException { // TODO Auto-generated method stub return null; } }, args); return jdbcTemplate.queryForObject( SQL_SELECT_SPITTER_BY_ID, new ParameterizedRowMapper<Spitter>() { public Spitter mapRow(ResultSet rs, int rowNum) throws SQLException { Spitter spitter = new Spitter(); spitter.setId(rs.getLong(1)); spitter.setUsername(rs.getString(2)); spitter.setPassword(rs.getString(3)); spitter.setFullName(rs.getString(4)); return spitter; } }, id); }
private EventStream getEventStream(final UUID streamId) { return jdbcTemplate.queryForObject( "select type, version, timestamp, next_event_sequence from event_stream where id = ?", new EventStreamRowMapper(streamId), streamId.toString()); }
/** * * given a fiscal year, get the first day of that fiscal year * @param universityFiscalYear = fiscal year (must be in the table) * @return the date on which the fiscal year passed as a parameter starts */ protected Date getFiscalYearStartDate(Integer universityFiscalYear) { return getSimpleJdbcTemplate().queryForObject(dateFetcher, Date.class, universityFiscalYear); }
public Spitter getSpitterById(long id) { return getSimpleJdbcTemplate().queryForObject( SQL_SELECT_SPITTER_BY_ID, new ParameterizedRowMapper<Spitter>() { public Spitter mapRow(ResultSet rs, int rowNum) throws SQLException { Spitter spitter = new Spitter(); spitter.setId(rs.getLong(1)); spitter.setUsername(rs.getString(2)); spitter.setPassword(rs.getString(3)); spitter.setFullName(rs.getString(4)); return spitter; } }, id); }
public Problem[] isPrepared() { List<Problem> ps = new ArrayList<Problem>(); if (jdbc == null) ps.add(new Problem("JdbcTemplate not set")); if (prepareScript == null) ps.add(new Problem("PrepareScript not set")); if (destroyScript == null) ps.add(new Problem("DestroyScript not set")); if (checkScript == null) { ps.add(new Problem("CheckScript not set")); } else { try { InputStream stream = getClass().getResourceAsStream(checkScript); if (stream == null) ps.add(new Problem("CheckScript not found: "+checkScript)); else if (!jdbc.queryForObject(IOUtils.toString(stream), Boolean.class)) ps.add(new Problem("Database is not configured")); } catch (DataAccessException e) { ps.add(new Problem("DataAccessException caught: "+e)); } catch (IOException e) { ps.add(new Problem("IOException caught: "+e)); } } if (ps.size()==0) return null; else return ps.toArray(new Problem[ps.size()]); }
public MutableResponseHeader loadResponseHeader(int id) throws DataAccessException { try { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(ID, id, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate( getNamedParameterJdbcTemplate()); return template.queryForObject(SELECT_RESPONSE, RESPONSE_MAPPER, params); } catch (EmptyResultDataAccessException erdae) { return null; } }
public byte[] loadMessageContent(int id) throws DataAccessException { try { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(ID, id, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate( getNamedParameterJdbcTemplate()); return template.queryForObject(SELECT_CONTENT, CONTENT_MAPPER, params); } catch (EmptyResultDataAccessException erdae) { return null; } }
public Conversation getConversation(int id) throws DataAccessException { try { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(ID, id, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate( getNamedParameterJdbcTemplate()); return template.queryForObject(SELECT_SUMMARY, CONVERSATION_MAPPER, params); } catch (EmptyResultDataAccessException erdae) { return null; } }
public RequestHeader loadRequestHeader(int id) throws DataAccessException { MapSqlParameterSource params = new MapSqlParameterSource(); try { params.addValue(ID, id, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate( getNamedParameterJdbcTemplate()); return template.queryForObject(SELECT_REQUEST, REQUEST_MAPPER, params); } catch (EmptyResultDataAccessException erdae) { return null; } }
public Book findBook(Integer bookId) { try { this.log.infof("Loading book [ID = %d]", bookId); return this.jdbcTemplate.queryForObject("SELECT * FROM books WHERE id = ?", new BookRowMapper(), bookId); } catch (EmptyResultDataAccessException e) { return null; } }