Example usage for org.springframework.jdbc.core PreparedStatementSetter PreparedStatementSetter

List of usage examples for org.springframework.jdbc.core PreparedStatementSetter PreparedStatementSetter

Introduction

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

Prototype

PreparedStatementSetter

Source Link

Usage

From source file:org.tibetjungle.demo.dao.ContactDaoImpl.java

public void create(final Contact contact) {
    getJdbcTemplate().update("insert into contacts values (?, ?, ?)", new PreparedStatementSetter() {
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setLong(1, contact.getId());
            ps.setString(2, contact.getName());
            ps.setString(3, contact.getEmail());
        }/*from   ww w .  j a  va 2  s.c  o m*/
    });
}

From source file:org.apache.lucene.store.jdbc.handler.MarkDeleteFileEntryHandler.java

public void deleteFile(final String name) throws IOException {
    jdbcTemplate.update(table.sqlMarkDeleteByName(), new PreparedStatementSetter() {
        @Override//w w w  .ja va  2  s  .co  m
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setFetchSize(1);
            ps.setBoolean(1, true);
            ps.setString(2, name);
        }
    });
}

From source file:edu.cmu.lti.oaqa.framework.log.impl.JdbcLogPersistenceProvider.java

@Override
public void log(final String uuid, final Trace trace, final LogEntry type, final String message) {
    System.out.printf("[logger] %s,%s,%s,%s,%s\n", new Date(), uuid, trace, type, message);
    String insert = (String) getParameterValue("insert-log-entry-query");
    DataStoreImpl.getInstance().jdbcTemplate().update(insert, new PreparedStatementSetter() {
        @Override//from   ww  w .j  av  a  2s .  co m
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setString(1, uuid);
            ps.setString(2, trace.getTraceHash());
            ps.setString(3, type.toString());
            ps.setString(4, message);
        }
    });
}

From source file:de.olivergierke.spring4.java8.JdbcRepository.java

public void executeQueryWithPreparedStatementAndRowMapper() {

    template.query("SELECT name, age FROM person WHERE dep = ?", ps -> ps.setString(1, "Sales"),
            (rs, rowNum) -> new Person(rs.getString(1), rs.getString(2)));

    // VS.//from  w  ww. ja  va2  s .c o  m

    template.query("SELECT name, age FROM person WHERE dep = ?", new PreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setString(1, "Sales");
        }
    }, new RowMapper<Person>() {
        @Override
        public Person mapRow(ResultSet resultSet, int i) throws SQLException {
            return new Person(rs.getString(1), rs.getString(2));
        }
    });
}

From source file:org.apache.lucene.store.jdbc.index.AbstractJdbcIndexOutput.java

public void close() throws IOException {
    super.close();
    final long length = length();
    doBeforeClose();//from   w ww .  j  a v a 2 s  . c o  m
    jdbcDirectory.getJdbcTemplate().update(jdbcDirectory.getTable().sqlInsert(), new PreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setFetchSize(1);
            ps.setString(1, name);
            InputStream is = null;
            try {
                is = openInputStream();
                if (jdbcDirectory.getDialect().useInputStreamToInsertBlob()) {
                    ps.setBinaryStream(2, is, (int) length());
                } else {
                    ps.setBlob(2, new InputStreamBlob(is, length));
                }
                ps.setLong(3, length);
                ps.setBoolean(4, false);
            } catch (IOException e) {
                throw new SQLException(e);
            }
        }
    });
    doAfterClose();
}

From source file:com.pontecultural.flashcards.JdbcFlashcardsDao.java

public void insert(final Card aCard) {
    String sql = "INSERT INTO cards (enText,ptText,deckId) VALUES (?,?,?)";
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.update(sql, new PreparedStatementSetter() {
        public void setValues(PreparedStatement ps) throws SQLException {
            int index = 1;
            ps.setString(index, aCard.getEnText());
            index++;//from  w  w  w  .  ja v a 2 s . co m
            ps.setString(index, aCard.getPtText());
            index++;
            ps.setInt(index, aCard.getDeckId());
        }
    });
}

From source file:sample.contact.dao.impl.MenuDaoImpl.java

public Menu create(final Menu menu) {
    getJdbcTemplate().update("insert into menus (menu_name, menu_path)values (?, ?)",
            new PreparedStatementSetter() {
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setString(1, menu.getName());
                    ps.setString(2, menu.getPath());
                }/*from  w w  w  .  ja v  a  2  s.  c  om*/
            });
    long id = getJdbcTemplate().queryForObject("select last_insert_id()", Long.class);
    return getById(id);
}

From source file:edu.cmu.lti.oaqa.openqa.hello.eval.passage.PassageMAPEvalPersistenceProvider.java

@Override
public void deletePassageAggrEval(final Key key, final String sequenceId) {
    final String name = getClass().getSimpleName();
    String insert = getDeletePassageAggrEval();
    DataStoreImpl.getInstance().jdbcTemplate().update(insert, new PreparedStatementSetter() {
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setString(1, key.getExperiment());
            ps.setString(2, key.getTrace().getTraceHash());
            ps.setString(3, name);//from  w  ww. ja v  a 2s .co m
            ps.setString(4, sequenceId);
        }
    });
}

From source file:org.tibetjungle.demo.dao.ContactDaoImpl.java

public void delete(final Long contactId) {
    getJdbcTemplate().update("delete from contacts where id = ?", new PreparedStatementSetter() {
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setLong(1, contactId);/*from  w w w  .  ja  v a 2 s .  c  o m*/
        }
    });
}

From source file:example.java8.JdbcRepository.java

/**
 * Shows the usage of//from w  w w .j av  a  2s  . c  o  m
 * {@link JdbcTemplate#query(org.springframework.jdbc.core.PreparedStatementCreator, org.springframework.jdbc.core.RowCallbackHandler)}
 * using Java 8 Lambda expressions in contrast to the traditional style.
 */
public void executeQueryWithPreparedStatementAndRowMapper() {

    template.query("SELECT name, age FROM person WHERE dep = ?", ps -> ps.setString(1, "Sales"),
            (rs, rowNum) -> new Person(rs.getString(1), rs.getString(2)));

    // VS.

    template.query("SELECT name, age FROM person WHERE dep = ?", new PreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setString(1, "Sales");
        }
    }, new RowMapper<Person>() {
        @Override
        public Person mapRow(ResultSet rs, int i) throws SQLException {
            return new Person(rs.getString(1), rs.getString(2));
        }
    });
}