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:info.novatec.flyway.branching.extension.BranchingMigrationPostgresqlIntegrationTest.java

/**
 * Cleaning up the test database./*  www.  j a  va 2 s .c o m*/
 * @throws InterruptedException if thread is interrupted
 */
@After
public final void cleanup() throws InterruptedException {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(getDatasource());
    try {
        jdbcTemplate.update("drop table person");
    } catch (DataAccessException e) {
        // No OP
    }
    try {
        jdbcTemplate.update("drop table releasetable");
    } catch (DataAccessException e) {
        // No OP
    }
    try {
        jdbcTemplate.update("drop table schema_version");
    } catch (DataAccessException e) {
        // No OP
    }
}

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

public void createTable() {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.update(
            "create table users (username VARCHAR(45) NOT NULL, password VARCHAR(45) NOT NULL, enabled TINYINT NOT NULL DEFAULT 1, PRIMARY KEY (username))");
    jdbcTemplate.update(/*from   ww  w  .  ja va 2s .c  om*/
            "create table user_roles (user_role_id int(11) NOT NULL AUTO_INCREMENT, username varchar(45) NOT NULL, role varchar(45) NOT NULL, PRIMARY KEY (user_role_id), UNIQUE KEY uni_username_role (role,username), KEY fk_username_idx (username), CONSTRAINT fk_username FOREIGN KEY (username) REFERENCES users (username))");
    jdbcTemplate.update(
            "create table persistent_logins (username varchar(64) not null, series varchar(64) not null, token varchar(64) not null, last_used timestamp not null, PRIMARY KEY (series))");

    jdbcTemplate.update("insert into users (username, password) values (?, ?)", "admin", "admin");
    jdbcTemplate.update("insert into users (username, password) values (?, ?)", "user", "user");
    jdbcTemplate.update("insert into user_roles (username, role) values (?, ?)", "admin", "ROLE_ADMIN");
    jdbcTemplate.update("insert into user_roles (username, role) values (?, ?)", "admin", "ROLE_USER");
    jdbcTemplate.update("insert into user_roles (username, role) values (?, ?)", "user", "ROLE_USER");
}

From source file:eionet.transfer.dao.MetadataServiceJdbc.java

@Override
public void deleteAll() {
    String query = "DELETE FROM uploads";
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.update(query);
}

From source file:io.cloudslang.engine.data.SimpleHiloIdentifierGenerator.java

private void updateCurrentChunk() {
    if (logger.isDebugEnabled()) {
        logger.debug("Updating HILO chunk...");
    }//from   ww  w .  ja v  a 2  s .c o m

    long t = System.currentTimeMillis();
    try (Connection conn = dataSource.getConnection()) {
        conn.setAutoCommit(false);
        JdbcTemplate jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(conn, true));

        jdbcTemplate.update(SQL_LOCK);
        currentChunk = jdbcTemplate.queryForObject(SQL_SELECT, Integer.class);
        if (logger.isDebugEnabled())
            logger.debug("Current chunk: " + currentChunk);
        jdbcTemplate.execute(SQL_UPDATE);
        jdbcTemplate.execute("commit");

        if (logger.isDebugEnabled()) {
            logger.debug("Updating HILO chunk done in " + (System.currentTimeMillis() - t) + " ms");
        }
        currentId = 0;
    } catch (SQLException e) {
        logger.error("Unable to update current chunk", e);
        throw new IllegalStateException("Unable to update current chunk");
    }
}

From source file:com.iucosoft.eavertizare.dao.impl.ClientsDaoImpl.java

@Override
public void deleletAll(Firma firma) {
    String query = "delete from " + firma.getTabelaClientiLocal() + " where id>0";
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    jdbcTemplate.update(query);
}

From source file:com.iucosoft.eavertizare.dao.impl.ClientsDaoImpl.java

@Override
public void deleletById(Firma firma, Client client) {

    String query = "delete from " + firma.getTabelaClientiLocal() + " where id=" + client.getId();
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    jdbcTemplate.update(query);
}

From source file:com.px100systems.data.plugin.persistence.jdbc.Storage.java

private void deleteRecord(JdbcTemplate jdbc, RawRecord record) {
    jdbc.update("DELETE FROM " + table + " WHERE unit_name = '" + record.getUnitName() + "' AND id = "
            + record.getId());/*from w ww.j av a 2  s. co m*/
}

From source file:com.thesoftwareguild.capstoneblog.dao.BlogDaoTest.java

@Before
public void setUp() {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("test-applicationContext.xml");
    JdbcTemplate jdbcTemplate = ctx.getBean("jdbcTemplate", org.springframework.jdbc.core.JdbcTemplate.class);

    // remove old data
    jdbcTemplate.update("DELETE from posts;");
    jdbcTemplate.update("DELETE from categories;");
    jdbcTemplate.update("DELETE from tags;");
    jdbcTemplate.update("DELETE from comments;");

    // Set status of test posts here
    post1.setStatus(PostStatus.PENDING);
    publishedPost1.setStatus(PostStatus.PUBLISHED);
    publishedPost2.setStatus(PostStatus.PUBLISHED);
    pendingPost1.setStatus(PostStatus.PENDING);
    pendingPost2.setStatus(PostStatus.PENDING);

    // Add test posts to Dao
    dao.addPost(post1);/*from   w  ww  .  j a  va 2  s  .co  m*/
    dao.addPost(publishedPost1);
    dao.addPost(publishedPost2);
    dao.addPost(pendingPost1);
    dao.addPost(pendingPost2);

}

From source file:com.test.sharksharding.use.resource.RedisResourceTest.java

public @Test void testInsert() {
    while (true) {
        System.out.println("input-->");
        Scanner scan = new Scanner(System.in);
        final String uid = scan.nextLine();
        JdbcTemplate jdbcTemlate = GetJdbcTemplate.getJdbcTemplate();
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("uid", Long.valueOf(uid));
        params.put("userName", "gaoxianglong");
        final String sql = sqlTemplate.getSql("setUserInfo", params);
        jdbcTemlate.update(sql);
    }/*w  w w  .  ja  v  a  2  s.c o m*/
}

From source file:db.postgres.V2_0_1__InitializeIdentityZones.java

private void removeDuplicateRows(final JdbcTemplate jdbcTemplate, final Long zone) {
    final List<SubjectEntity> subjects = jdbcTemplate
            .query("SELECT DISTINCT subject_identifier, attributes FROM subject", new SubjectRowMapper());
    jdbcTemplate.update("DELETE FROM subject *");
    for (SubjectEntity s : subjects) {
        jdbcTemplate.update(//  w  ww  .  j  av a  2 s .c  o m
                "INSERT INTO subject (subject_identifier, attributes, "
                        + " authorization_zone_id) VALUES (?,?,?)",
                s.getSubjectIdentifier(), s.getAttributesAsJson(), zone);
    }
    final List<ResourceEntity> resources = jdbcTemplate
            .query("SELECT DISTINCT resource_identifier, attributes FROM resource", new ResourceRowMapper());
    jdbcTemplate.update("DELETE FROM resource *");
    for (ResourceEntity r : resources) {
        jdbcTemplate.update(
                "INSERT INTO resource (resource_identifier, attributes, "
                        + " authorization_zone_id) VALUES (?,?,?)",
                r.getResourceIdentifier(), r.getAttributesAsJson(), zone);
    }

    final List<PolicySetEntity> policysets = jdbcTemplate
            .query("SELECT DISTINCT policy_set_id, policy_set_json FROM policy_set", new PolicySetRowMapper());
    jdbcTemplate.update("DELETE FROM policy_set *");
    for (PolicySetEntity ps : policysets) {
        SqlRowSet row = jdbcTemplate.queryForRowSet("SELECT * FROM policy_set WHERE policy_set_id =?",
                ps.getPolicySetID());
        if (row.next()) {
            jdbcTemplate.update("UPDATE policy_set SET policy_set_json = ? WHERE policy_set_id = ?",
                    ps.getPolicySetJson(), ps.getPolicySetID());
        } else {
            jdbcTemplate.update(
                    "INSERT INTO policy_set (policy_set_id, policy_set_json, "
                            + " authorization_zone_id) VALUES (?,?,?)",
                    ps.getPolicySetID(), ps.getPolicySetJson(), zone);
        }
    }
}