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

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

Introduction

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

Prototype

public JdbcTemplate(DataSource dataSource) 

Source Link

Document

Construct a new JdbcTemplate, given a DataSource to obtain connections from.

Usage

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

public int update(String username, String password, String enabled) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    int result = jdbcTemplate.update("update into users set password = ?, enabled = ? where username = ? ",
            password, Integer.parseInt(enabled), username);

    return result;
}

From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java

public JdbcTemplate getJdbcTemplate() {
    if (jdbcTemplate == null) {
        jdbcTemplate = new JdbcTemplate(dataSource);
    }
    return jdbcTemplate;
}

From source file:com.netflix.simianarmy.aws.RDSRecorder.java

/**
 * Instantiates a new RDS recorder.//from   www .  ja v  a2 s. c  o  m
 *
 */
public RDSRecorder(String dbDriver, String dbUser, String dbPass, String dbUrl, String dbTable, String region) {
    HikariDataSource dataSource = new HikariDataSource();
    dataSource.setDriverClassName(dbDriver);
    dataSource.setJdbcUrl(dbUrl);
    dataSource.setUsername(dbUser);
    dataSource.setPassword(dbPass);
    dataSource.setMaximumPoolSize(2);
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    this.table = dbTable;
    this.region = region;
}

From source file:org.anon.exec.AbstractExec.java

protected int update(String sql, Object... args) {
    Logger.getLogger(getClass()).log(Level.DEBUG, "Updating " + sql + "\n Params: " + Arrays.toString(args));
    return new JdbcTemplate(dataSource).update(sql, args);
}

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

@Override
public void deleteByName(String firmaName) {
    String query = "delete from firme where nume_firma=?";
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    jdbcTemplate.update(query, firmaName);
}

From source file:net.sourceforge.vulcan.spring.jdbc.JdbcSchemaMigratorTest.java

public void testUpdateSchemaCreatesTables() throws Exception {
    migrator.setMigrationScripts(new Resource[0]);
    migrator.updateSchema();/*from   ww w .j  a  v a  2  s.c  o  m*/

    int count = new JdbcTemplate(dataSource).queryForInt("select count(1) from builds");
    assertEquals(0, count);
}

From source file:com.seajas.search.profiler.service.profiler.dao.ModifierDAO.java

/**
 * Initialize the database tables./*from w w  w.ja va2s.com*/
 * 
 * @param dataSource
 */
@Autowired
public ModifierDAO(final DataSource dataSource) {
    this.jdbc = new JdbcTemplate(dataSource);

    try {
        jdbc.execute(
                "CREATE TABLE modifier (id INT NOT NULL PRIMARY KEY, url_type VARCHAR(255) NOT NULL, url_expression VARCHAR(255) NOT NULL, test_feed_id INT DEFAULT NULL, is_enabled INTEGER DEFAULT 1)");
        jdbc.execute("CREATE SEQUENCE seq_modifier AS INTEGER");
    } catch (DataAccessException e) {
        if (logger.isDebugEnabled())
            logger.debug("Table 'modifier' likely already exists as it could not be created");
    }

    try {
        jdbc.execute(
                "CREATE TABLE modifier_filter (id INT NOT NULL PRIMARY KEY, modifier_id INTEGER NOT NULL, fragment_start VARCHAR(1024) NOT NULL, fragment_end VARCHAR(1024) NOT NULL, is_expression INTEGER DEFAULT 1)");
        jdbc.execute("CREATE SEQUENCE seq_modifier_filter AS INTEGER");
    } catch (DataAccessException e) {
        if (logger.isDebugEnabled())
            logger.debug("Table 'modifier_filter' likely already exists as it could not be created");
    }

    try {
        jdbc.execute(
                "CREATE TABLE modifier_script (id INT NOT NULL PRIMARY KEY, modifier_id INTEGER NOT NULL, modification_date DATETIME NOT NULL, script_language VARCHAR(255) NOT NULL, script_content VARCHAR(65535) NOT NULL)");
        jdbc.execute("CREATE SEQUENCE seq_modifier_script AS INTEGER");
    } catch (DataAccessException e) {
        if (logger.isDebugEnabled())
            logger.debug(
                    "Tables 'modifier', 'modifier_filter' and 'modifier_script' likely already exist as they could not be created");
    }
}

From source file:com.sfs.whichdoctor.dao.BaseDAOImpl.java

/**
 * Gets the jdbc template reader.//from  www. j  a  va  2  s.  c  o m
 *
 * @return the jdbc template reader
 */
protected final JdbcTemplate getIsbJdbcTemplate() {
    return new JdbcTemplate(isbDataSource);
}