List of usage examples for org.springframework.jdbc.core PreparedStatementSetter PreparedStatementSetter
PreparedStatementSetter
From source file:com.leapfrog.sms.dao.impl.CourseDAOImpl.java
@Override public List<Course> search(String param) { final String parameter = param; PreparedStatementSetter setter = new PreparedStatementSetter() { @Override// w w w.j ava 2 s . c o m public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, "%" + parameter + "%"); } }; return jdbcTemplate.query(SqlConstant.COURSE_SEARCH, setter, new RowMapper<Course>() { @Override public Course mapRow(ResultSet rs, int i) throws SQLException { return mapData(rs); } }); }
From source file:org.tibetjungle.demo.dao.ContactDaoImpl.java
public void update(final Contact contact) { getJdbcTemplate().update("update contacts set contact_name = ?, address = ? where id = ?", new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, contact.getName()); ps.setString(2, contact.getEmail()); ps.setLong(3, contact.getId()); }/*from w w w. j a va 2s . co m*/ }); }
From source file:sample.contact.dao.impl.MenuDaoImpl.java
public void delete(final Long menuId) { getJdbcTemplate().update("delete from menus where id = ?", new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setLong(1, menuId);//w ww .j a v a2s.co m } }); }
From source file:com.pontecultural.flashcards.JdbcFlashcardsDao.java
public int insert(final Deck aDeck) { int rc = -1;//from w w w . j a v a 2 s.c o m String sql = "INSERT INTO decks (name, description) VALUES (?,?)"; JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.update(sql, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { int index = 1; ps.setString(index, aDeck.getName()); index++; ps.setString(index, aDeck.getDescription()); } }); // There are database specific ways to retrieve the id // for the last inserted row(e.g., last_insert_id() in // mysql. Using MAX(id) because I want to be able to use // different data sources. See Stackoverflow for limitations // on this approach. // http://stackoverflow.com/questions/4734589/retrieve-inserted-row-id-in-sql/4734672 rc = jdbcTemplate.queryForInt("SELECT MAX(_id) from decks"); return rc; }
From source file:com.taobao.diamond.server.service.DBPersistService.java
public void addConfigInfo(final Timestamp time, final ConfigInfo configInfo) { this.jt.update( "insert into config_info (data_id,group_id,content,md5,gmt_create,gmt_modified) values(?,?,?,?,?,?)", new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { int index = 1; ps.setString(index++, configInfo.getDataId()); ps.setString(index++, configInfo.getGroup()); ps.setString(index++, configInfo.getContent()); ps.setString(index++, configInfo.getMd5()); ps.setTimestamp(index++, time); ps.setTimestamp(index++, time); }/*from w w w .ja v a 2s . c om*/ }); }
From source file:edu.cmu.lti.oaqa.openqa.hello.eval.passage.PassageMAPEvalPersistenceProvider.java
@Override public void insertPartialCounts(final Key key, final String sequenceId, final PassageMAPCounts counts) throws SQLException { final String eName = getClass().getSimpleName(); String insert = getInsertPassageAggregates(); final Trace trace = key.getTrace(); DataStoreImpl.getInstance().jdbcTemplate().update(insert, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, key.getExperiment()); ps.setString(2, trace.getTrace()); ps.setString(3, eName);//from w w w. j a va2 s . c o m ps.setFloat(4, counts.getDocavep()); ps.setFloat(5, counts.getPsgavep()); ps.setFloat(6, counts.getAspavep()); ps.setFloat(7, counts.getCount()); ps.setString(8, sequenceId); ps.setInt(9, key.getStage()); ps.setString(10, trace.getTraceHash()); } }); }
From source file:sample.contact.dao.impl.MenuDaoImpl.java
public int update(final Menu menu) { return getJdbcTemplate().update("update menus set menu_name = ?, menu_path = ? where id = ?", new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, menu.getName()); ps.setString(2, menu.getPath()); ps.setLong(3, menu.getId()); }/* w w w . j a v a 2s. co m*/ }); }
From source file:net.duckling.ddl.service.param.dao.ParamDAOImpl.java
@Override public void create(final Param param) { getJdbcTemplate().update(INSERT_PARAM, new PreparedStatementSetter() { @Override/*from www .ja v a 2 s.c o m*/ public void setValues(PreparedStatement ps) throws SQLException { int i = 0; ps.setString(++i, param.getItemId()); ps.setString(++i, param.getKey()); ps.setString(++i, param.getValue()); ps.setString(++i, param.getType()); } }); }
From source file:com.starit.diamond.server.service.DBPersistService.java
public void addConfigInfo(final Timestamp time, final ConfigInfo configInfo) { final Long id = this.jt.queryForObject("SELECT MAX(ID) FROM config_info", Long.class); this.jt.update( "insert into config_info (id, data_id,group_id, username, content,md5,gmt_create,gmt_modified, description) values(?,?,?,?,?,?,?,?,?)", new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { int index = 1; if (id == null) ps.setLong(index++, 1); else ps.setLong(index++, (Long) id + 1); ps.setString(index++, configInfo.getDataId()); ps.setString(index++, configInfo.getGroup()); ps.setString(index++, configInfo.getUserName()); ps.setString(index++, configInfo.getContent()); ps.setString(index++, configInfo.getMd5()); ps.setTimestamp(index++, time); ps.setTimestamp(index++, time); ps.setString(index++, configInfo.getDescription()); }/* ww w.ja v a2 s. c o m*/ }); }
From source file:com.surevine.alfresco.audit.repo.JdbcAuditRepository.java
/** * Simple write to the database of the audit object. * // ww w . j a v a 2 s . co m * @see com.surevine.alfresco.audit.AuditRepository#audit(com.surevine.alfresco.audit.Auditable) */ public void audit(final Auditable toAudit) { this.jdbcTemplate.update(UPDATE_SQL, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, truncate(toAudit.getUser(), 40)); ps.setString(2, truncate(toAudit.getAction(), 40)); ps.setString(3, truncate(toAudit.getSource(), 80)); ps.setString(4, truncate(toAudit.getSecLabel(), 1024)); ps.setString(5, truncate(toAudit.getSite(), 80)); ps.setString(6, truncate(toAudit.getDetails(), 256)); ps.setString(7, truncate(toAudit.getUrl(), 256)); ps.setString(8, truncate(toAudit.getVersion(), 10)); ps.setTimestamp(9, new java.sql.Timestamp(System.currentTimeMillis())); ps.setString(10, truncate(toAudit.getRemoteAddress(), 40)); ps.setString(11, Boolean.toString(toAudit.isSuccess())); ps.setString(12, truncate(toAudit.getTags(), 256)); ps.setString(13, truncate(toAudit.getNodeRef(), 80)); ps.setLong(14, toAudit.getTimeSpent()); } }); }