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:org.beast.project.template.config.MyBatisConfig.java

@Override
public DataSource dataSource() {

    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    //DataSource ds = builder.setType(EmbeddedDatabaseType.HSQL).addScript("schema.sql").build();
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName(org.hsqldb.jdbcDriver.class.getName());
    basicDataSource.setUsername("sa");
    basicDataSource.setPassword("");
    basicDataSource.setUrl("jdbc:hsqldb:mem:mydb");
    JdbcTemplate jdbcTemplate = new JdbcTemplate(basicDataSource);
    System.out.println("Creating tables");
    jdbcTemplate.execute("drop table person if exists");
    jdbcTemplate.execute("create table person(id serial, firstName varchar(50), lastName varchar(50))");
    jdbcTemplate.update("INSERT INTO users(firstName, lastName) values (?,?)", "Mike", "Lanyon");
    return basicDataSource;
}

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

public void insert(String username, String series, String token, Date date) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.update(//from  w  ww  .j  ava  2  s  . c  om
            "insert into persistent_logins (username, series, token, last_used) values (?, ?, ?, ?)", username,
            series, token, date);
}

From source file:be.jacobsvanroy.springsqlunit.IntegrationTest.java

public static List<String> getResults() {
    return new JdbcTemplate(DATA_SOURCE).queryForList("select col from spring_sql_test", String.class);
}

From source file:org.cloudfoundry.identity.uaa.scim.job.AdminUsersTasklet.java

public void setDataSource(DataSource dataSource) {
    jdbcTemplate = new JdbcTemplate(dataSource);
}

From source file:org.cloudfoundry.identity.uaa.scim.job.BackwardMigrationJobIntegrationTests.java

@Test
public void testJobRuns() throws Exception {
    TestUtils.deleteFrom(cloudControllerDataSource, "users");
    TestUtils.deleteFrom(uaaDataSource, "users");
    JdbcTemplate uaaTemplate = new JdbcTemplate(uaaDataSource);
    uaaTemplate.update(/*from  w ww .  j  a v a  2s.  c o m*/
            "insert into users "
                    + "(id, active, userName, email, password, familyName, givenName, created, lastModified) "
                    + "values (?, ?, ?, ?, ?, ?, ?, ?, ?)",
            "FOO", true, "uniqua", "uniqua@test.org", "ENCRYPT_ME", "Una", "Uniqua", new Date(), new Date());
    JobExecution execution = jobLauncher.run(job,
            new JobParametersBuilder().addDate("start.date", new Date(0L)).toJobParameters());
    assertEquals(BatchStatus.COMPLETED, execution.getStatus());
    Iterator<StepExecution> iterator = execution.getStepExecutions().iterator();
    StepExecution step = iterator.next();
    assertEquals(1, step.getReadCount());
    assertEquals(1, step.getWriteCount());
    JdbcTemplate jdbcTemplate = new JdbcTemplate(cloudControllerDataSource);
    assertEquals(1, jdbcTemplate.queryForInt("select count(*) from users"));
}

From source file:org.cloudfoundry.identity.uaa.scim.job.UserMigrationJobIntegrationTests.java

@Test
public void testJobRuns() throws Exception {

    TestUtils.deleteFrom(cloudControllerDataSource, "users");
    TestUtils.deleteFrom(uaaDataSource, "users");
    new JdbcTemplate(cloudControllerDataSource).update(
            "insert into users (id, active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?, ?)",
            4, true, "invalid", "ENCRYPT_ME", new Date(), new Date());
    new JdbcTemplate(cloudControllerDataSource).update(
            "insert into users (id, active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?, ?)",
            4, true, "vcap_tester@vmware.com", "ENCRYPT_ME", new Date(), new Date());
    JobExecution execution = jobLauncher.run(job,
            new JobParametersBuilder().addString("users", "marissa@test.org,vcap_tester@vmware.com")
                    .addLong("run.id", 0L).toJobParameters());
    assertEquals(BatchStatus.COMPLETED, execution.getStatus());
    Iterator<StepExecution> iterator = execution.getStepExecutions().iterator();
    assertEquals(1, iterator.next().getWriteCount());
    assertEquals(1, iterator.next().getWriteCount());
    JdbcTemplate jdbcTemplate = new JdbcTemplate(uaaDataSource);
    assertEquals(1, jdbcTemplate.queryForInt("select count(*) from users"));
    assertEquals(1,/* ww  w.ja va 2s. com*/
            jdbcTemplate.queryForInt("select count(*) from users where authorities=?", "uaa.admin,uaa.user"));
}

From source file:com.alibaba.otter.node.etl.common.datasource.AbstractDbDialectTest.java

@Test
public void testFindTable() throws Exception {
    DataSource dataSource = createDataSource("jdbc:oracle:thin:@127.0.0.1:1521:OINTEST", "otter1", "jonathan",
            "oracle.jdbc.OracleDriver", DataMediaType.ORACLE, "utf-8");
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    Table table = DdlUtils.findTable(jdbcTemplate, "otter1".toUpperCase(), "otter1".toUpperCase(),
            "wytable3".toUpperCase());
    System.out.println("the tablename = " + table.getSchema() + "." + table.getName());
    Column[] columns = table.getColumns();
    for (Column column : columns) {
        System.out.println("columnName = " + column.getName() + ",columnType = " + column.getTypeCode()
                + ",isPrimary = " + column.isPrimaryKey() + ",nullable = " + column.isRequired());
    }/* w ww  .  ja v  a2  s .c  o  m*/

}

From source file:com.github.jrrdev.mantisbtsync.core.common.CommonConfiguration.java

@Bean
public JdbcTemplate jdbcTemplate(final DataSource dataSource) {
    return new JdbcTemplate(dataSource);
}

From source file:com.gzj.tulip.jade.dataaccess.DataAccessImpl.java

public DataAccessImpl(DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
}

From source file:ru.org.linux.group.GroupDao.java

@Autowired
public void setDateSource(DataSource ds) {
    jdbcTemplate = new JdbcTemplate(ds);
}