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.springsource.greenhouse.events.load.NFJSLoaderTest.java

@Before
public void setup() {
    db = new GreenhouseTestDatabaseBuilder().member().group().activity().invite().venue().event()
            .testData("com/springsource/greenhouse/events/load/JdbcEventLoaderRepositoryTest.sql")
            .getDatabase();/*from   w  ww . j a v  a 2  s  .co  m*/
    jdbcTemplate = new JdbcTemplate(db);
    eventLoaderRepository = new JdbcEventLoaderRepository(jdbcTemplate);
    loader = new NFJSLoader(eventLoaderRepository);
}

From source file:ch.digitalfondue.npjt.query.DateTimeQueriesTest.java

@Test
public void dateQueriesTest() {
    QueryFactory qf = new QueryFactory("hsqldb", new JdbcTemplate(dataSource));

    qf.addColumnMapperFactory(new ZonedDateTimeMapper.Factory());
    qf.addParameterConverters(new ZonedDateTimeMapper.Converter());

    qf.addColumnMapperFactory(new LocalDateMapper.Factory());
    qf.addParameterConverters(new LocalDateMapper.Converter());

    qf.addColumnMapperFactory(new LocalDateTimeMapper.Factory());
    qf.addParameterConverters(new LocalDateTimeMapper.Converter());

    qf.addColumnMapperFactory(new InstantMapper.Factory());
    qf.addParameterConverters(new InstantMapper.Converter());

    DateQueries dq = qf.from(DateQueries.class);

    dq.createTable();/* ww w .  j  a v a  2s.co m*/

    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));

    dq.insertValue("KEY", now);
    check(dq, "KEY", now);

    dq.insertValue("KEY2", now.toLocalDate());
    check(dq, "KEY2", now.toLocalDate());

    dq.insertValue("KEY3", now.toLocalDateTime());
    check(dq, "KEY3", now);

    Instant iNow = Instant.now();
    dq.insertValue("KEY4", iNow);
    Assert.assertEquals(iNow, dq.findInstantByKey("KEY4"));
    Assert.assertEquals(iNow, dq.findConfInstantByKey("KEY4").value);

}

From source file:io.github.huherto.springyRecords.BaseTable.java

public BaseTable(DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    insertCommand = new SimpleJdbcInsert(dataSource);
    insertCommand.withTableName(tableName());

    autoIncrementField = RecordUtils.autoIncrementField(recordClass());
    if (autoIncrementField != null) {
        insertCommand.setGeneratedKeyName(autoIncrementField.getAnnotation(Column.class).name());
    }/*from  ww w .j a va2  s.c  om*/
}

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  w w w .j av  a  2  s  .  c  o m*/

}

From source file:com.springsource.greenhouse.events.load.JdbcEventLoaderRepositoryTest.java

@Before
public void setup() {
    db = new GreenhouseTestDatabaseBuilder().member().group().activity().invite().venue().event()
            .testData(getClass()).getDatabase();
    jdbcTemplate = new JdbcTemplate(db);
    eventLoaderRepository = new JdbcEventLoaderRepository(jdbcTemplate);
    eventRepository = new JdbcEventRepository(jdbcTemplate);
}

From source file:ru.org.linux.spring.StatUpdater.java

@Autowired
public void setDataSource(DataSource dataSource) {
    statUpdate = new SimpleJdbcCall(dataSource).withFunctionName("stat_update");
    statUpdate2 = new SimpleJdbcCall(dataSource).withFunctionName("stat_update2");
    statMonthly = new SimpleJdbcCall(dataSource).withFunctionName("update_monthly_stats");
    jdbcTemplate = new JdbcTemplate(dataSource);
}

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

public void delete(String username) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.update("delete from persistent_logins where username = ?", username);
}

From source file:com.github.fedorchuck.webstore.dao.impl.postgresql.JdbcCommodityRepositoryTest.java

@Before
@Ignore/*from  w ww.j av a 2 s  .  co m*/
public void setUp() {
    try {
        //TODO: should be rewritten.

        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(Config.DRIVERCLASSNAME);
        dataSource.setUrl(Config.URL);
        dataSource.setUsername(Config.USERNAME);
        dataSource.setPassword(Config.PASSWORD);
        jdbc = new JdbcCommodityRepository(new JdbcTemplate(dataSource));
        //TODO: run creating scripts.
        Assert.assertTrue(true);
    } catch (Throwable throwable) {
        Assert.fail(throwable.getMessage());
    }
}

From source file:org.jasig.cas.ticket.registry.support.JdbcLockingStrategyTests.java

/**
 * @throws  Exception on test setup.//  www.  j  a  va2  s . c  o m
 */
public void setUp() throws Exception {
    super.setUp();
    this.testDataSource = new SimpleDriverDataSource(new org.hsqldb.jdbcDriver(), "jdbc:hsqldb:mem:locktest",
            "sa", "");
    final JdbcTemplate tmpl = new JdbcTemplate(this.testDataSource);
    tmpl.execute(CREATE_TABLE_SQL);
    tmpl.execute(CREATE_PRI_KEY_SQL);
}

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

@Override
public void delete(int idConfiguratie) {

    String query = "delete from configuratii_db where id=?";
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    jdbcTemplate.update(query, idConfiguratie);

}