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

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

Introduction

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

Prototype

@Override
    public int update(PreparedStatementCreator psc) throws DataAccessException 

Source Link

Usage

From source file:com.javacreed.examples.spring.CreateBigTable.java

public static void main(final String[] args) throws Exception {

    final ComboPooledDataSource ds = DbUtils.createDs();
    try {/*from   w  ww. j a  v a 2s.com*/
        final JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);

        CreateBigTable.LOGGER.debug("Dropping table (if exists)");
        jdbcTemplate.update("DROP TABLE IF EXISTS `big_table`");

        CreateBigTable.LOGGER.debug("Creating table");
        jdbcTemplate.update("CREATE TABLE `big_table`(`id` INT(20), `name` VARCHAR(128))");

        CreateBigTable.LOGGER.debug("Adding records");
        final StringBuilder query = new StringBuilder();
        for (int i = 0, b = 1; i < 1000000; i++) {
            if (i % 500 == 0) {
                if (i > 0) {
                    CreateBigTable.LOGGER.debug("Adding records (batch {})", b++);
                    jdbcTemplate.update(query.toString());
                    query.setLength(0);
                }

                query.append("INSERT INTO `big_table` (`id`, `name`) VALUES ");
            } else {
                query.append(",");
            }

            query.append("  (" + (i + 1) + ", 'Pack my box with five dozen liquor jugs.')");
        }

        CreateBigTable.LOGGER.debug("Adding last batch");
        jdbcTemplate.update(query.toString());
    } finally {
        DbUtils.closeQuietly(ds);
    }

    CreateBigTable.LOGGER.debug("Done");
}

From source file:com.charandeepmatta.database.di.Schema.java

private static void updateSqlTo(final JdbcTemplate jdbc, final InputStream inputStream) throws IOException {
    String sqlFileAsString = IOUtils.toString(inputStream);
    jdbc.update(sqlFileAsString);
}

From source file:org.springside.modules.test.data.H2Fixtures.java

/**
 * , disable.//from www .jav a  2 s. c o m
 */
public static void deleteTable(DataSource dataSource, String... tableNames) {
    JdbcTemplate template = new JdbcTemplate(dataSource);

    template.update("SET REFERENTIAL_INTEGRITY FALSE");

    for (String tableName : tableNames) {
        template.update("DELETE FROM " + tableName);
    }

    template.update("SET REFERENTIAL_INTEGRITY TRUE");
}

From source file:transaction.script.ProjectTrScript.java

/**
 * @param template/* w w w.  ja  va2  s  .c om*/
 * @param query
 * @return
 * @throws SQLException
 */
public static boolean query(JdbcTemplate template, String query, Integer minAffectedValue,
        Integer maxAffectedValue) throws SQLException {
    logger.info("Query to execute is: " + query);

    int resultInt = template.update(query);
    int affectedCase = Utils.checkAffectedParams(minAffectedValue, maxAffectedValue);

    switch (affectedCase) {
    case IConstants.AffectedTypes.INFINITY_RANGE:
        return resultInt >= minAffectedValue;
    case IConstants.AffectedTypes.VALUE:
        return resultInt == minAffectedValue;
    case IConstants.AffectedTypes.RANGE:
        return resultInt >= minAffectedValue && resultInt <= maxAffectedValue;
    default:
        return false;
    }
}

From source file:com.googlecode.flyway.core.dbsupport.sqlserver.large.V3_1_3__Insert_tipos_de_eventos_padroes.java

public void migrate(JdbcTemplate jdbc) throws Exception {
    jdbc.update("INSERT INTO EVENTO_TIPO VALUES ('Casamento')");
}

From source file:com.dai.dao.CompeticaoDaoImpl.java

@Override
public void apagaCompeticao(int idCompeticao) {

    String sql = "delete from competicao where idCompeticao =" + idCompeticao;
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.update(sql);

}

From source file:com.dai.dao.SelecaoJogoDaoImpl.java

@Override
public void apagaSL(int idUtilizador, int idJogo) {

    String sql = "delete from selecaoJogo where utilizador_idUtilizador =" + idUtilizador + "and jogo_idJogo ="
            + idJogo;/*from   w ww . j  a  v  a2 s  .  c  o m*/
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.update(sql);

}

From source file:com.dai.dao.EscalaoDaoImpl.java

@Override
public void apagarEscalao(Integer id) {
    String sql = "delete from escalao where idEscalao=" + id;
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.update(sql);

}

From source file:com.dai.dao.PerfilDaoImpl.java

@Override
public void apagarPerfil(Integer id) {
    String sql = "delete from perfil where idPerfil=" + id;
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.update(sql);

}

From source file:com.company.project.service.dao.PersistentTokenDao.java

public void createTable() {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.update("create table messages (messagekey varchar(20), message varchar(100))");
}