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:eionet.transfer.dao.MetadataServiceJdbc.java

@Override
public Upload getById(String id) {
    String query = "SELECT id, expires, filename, uploader, contenttype, filesize FROM uploads WHERE id = ?";
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    Upload uploadRec = jdbcTemplate.queryForObject(query, new Object[] { id }, new RowMapper<Upload>() {

        @Override//ww  w . j  av  a  2  s .  c  om
        public Upload mapRow(ResultSet rs, int rowNum) throws SQLException {
            Upload uploadRec = new Upload();
            uploadRec.setId(rs.getString("id"));
            uploadRec.setFilename(rs.getString("filename"));
            uploadRec.setExpires(rs.getDate("expires"));
            uploadRec.setUploader(rs.getString("uploader"));
            uploadRec.setContentType(rs.getString("contenttype"));
            uploadRec.setSize(rs.getLong("filesize"));
            return uploadRec;
        }
    });

    return uploadRec;
}

From source file:org.smigo.species.KitchenGardenAidDataTest.java

@Autowired
public void setDataSource(javax.sql.DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
}

From source file:org.openinfinity.core.spring.JdbcPropertyPlaceholderConfigurer.java

/**
 * Public constructor for the class.//from   www  .j  a  v a2 s.  c o m
 * 
 * @param dataSource Represents the shared database data source.
 */
public JdbcPropertyPlaceholderConfigurer(DataSource dataSource) {
    super();
    Assert.notNull(dataSource,
            "Please define data source for reading properties from the shared data repository.");
    this.jdbcTemplate = new JdbcTemplate(dataSource);
}

From source file:org.jboss.fuse.examples.jdbc.DatabaseBean.java

public void destroy() throws Exception {
    JdbcTemplate jdbc = new JdbcTemplate(dataSource);

    try {/*w w  w.ja v a2 s  . c om*/
        jdbc.execute("drop table ALIEN");
    } catch (Throwable e) {
        // ignore
    }
}

From source file:org.cloudfoundry.identity.uaa.audit.JdbcFailedLoginCountingAuditServiceTests.java

@Before
public void createService() throws Exception {
    template = new JdbcTemplate(dataSource);
    auditService = new JdbcFailedLoginCountingAuditService(dataSource);
    template.execute(/*from  ww w  .ja  v  a  2  s  .  com*/
            "DELETE FROM sec_audit WHERE principal_id='1' or principal_id='clientA' or principal_id='clientB'");
    authDetails = "1.1.1.1";
}

From source file:com.wwpass.cas.support.dao.JdbcWwpassDao.java

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

From source file:org.smigo.species.JdbcSpeciesDao.java

@Autowired
public void setDataSource(DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    this.insertSpecies = new SimpleJdbcInsert(dataSource).withTableName("species")
            .usingGeneratedKeyColumns("id").usingColumns("creator");
}

From source file:com.beezas.dao.ContactDaoImpl.java

@Override
public List<ContDrpDwns> getMediaNam() {
    List mediaNam = new ArrayList();
    String sql = "SELECT * FROM MEDIA";
    jdbcTemplate = new JdbcTemplate(dataSource);
    mediaNam = jdbcTemplate.query(sql, new ContDrpDwnRowMapper());
    System.out.println("Present in DaoImpl mediavalues " + mediaNam);
    return mediaNam;
}

From source file:com.springsource.greenhouse.settings.SettingsControllerTest.java

@Before
public void setup() {
    db = new GreenhouseTestDatabaseBuilder().member().connectedApp().testData(getClass()).getDatabase();
    tokenStore = new JdbcTokenStore(db);
    jdbcTemplate = new JdbcTemplate(db);
    controller = new SettingsController(tokenStore, jdbcTemplate);

    AuthorizationRequest authorizationRequest = new DefaultAuthorizationRequest(
            "a08318eb478a1ee31f69a55276f3af64", Arrays.asList("read", "write"));
    Authentication userAuthentication = new UsernamePasswordAuthenticationToken("1", "whateveryouwantittobe");
    tokenStore.storeAccessToken(new DefaultOAuth2AccessToken("authme"),
            new OAuth2Authentication(authorizationRequest, userAuthentication));
    assertEquals(1, tokenStore.findTokensByUserName("1").size());
}

From source file:nz.geek.caffe.spring.ase.AseExceptionMappingTest.java

/**
 * Setup.//from   w w  w  . j a  v a2  s .  c  om
 */
@Before
public void setup() {
    this.datasource = new DriverManagerDataSource(
            System.getProperty("jdbcUrl", "jdbc:sybase:Tds:localhost:5000/test"),
            System.getProperty("jdbcUser", "spring"), System.getProperty("jdbcPassword", "spring"));

    this.jdbcTemplate = new JdbcTemplate(this.datasource);

    dropTables();

    this.jdbcTemplate.execute("create table TEST_PARENT(ID_ int, STR_ varchar(10), primary key (ID_))");
    this.jdbcTemplate.execute(
            "create table TEST_CHILD(ID_ int, STR_ varchar(10), PARENT_ int not null, primary key (ID_))");

    this.jdbcTemplate.execute(
            "alter table TEST_CHILD add constraint FK_PARENT_CHILD foreign key (PARENT_) references TEST_PARENT(ID_)");
}