List of usage examples for org.springframework.jdbc.core JdbcTemplate execute
@Override public void execute(final String sql) throws DataAccessException
From source file:test.service.SearchBankServiceTest.java
@Before public void init() { JdbcTemplate jdbc = new JdbcTemplate(dataSource); jdbc.execute("delete from banktable"); banks = creatListOfBanks();/*from ww w. ja v a 2 s. co m*/ bankDao.updateDB(banks); }
From source file:com.github.totyumengr.minicubes.cluster.DiscardController.java
@RequestMapping(value = "/dummyMerge", method = { RequestMethod.POST, RequestMethod.GET }) public @ResponseBody String mergePrepare(@NotBlank @RequestParam String timeSeries, @RequestParam String sql) { LOGGER.info("Try to merge data to {}.", sql, timeSeries); JdbcTemplate template = new JdbcTemplate(dataSource); template.afterPropertiesSet();//from w w w.j a va 2 s. c o m template.execute(sql); LOGGER.info("Success for merge data to {}.", sql, timeSeries); return OK; }
From source file:io.github.huherto.springyRecords.TestDatabaseGenerator.java
@Test @Ignore/* w ww. j a v a 2 s. c o m*/ public void insertPet() { DataSource ds = createDs(); JdbcTemplate jt = new JdbcTemplate(ds); jt.execute("delete from pet"); PetTable table = new PetTable(ds); PetRecord r = new PetRecord(); r.birthDate = new Date(); r.name = "Manchas"; r.owner = "Humberto"; r.sex = "M"; r.species = "Dog"; table.insert(r); List<PetRecord> pets = table.queryAll(); assertTrue(pets.size() >= 1); }
From source file:job_agency.job_agency.beans.DatabaseBean.java
public void destroy() throws Exception { JdbcTemplate jdbc = new JdbcTemplate(dataSource); try {// w w w .j a va 2s . c o m jdbc.execute("drop table person"); jdbc.execute("drop table joboffer"); } catch (Throwable e) { // ignore } }
From source file:org.springsource.examples.expenses.TestDatabaseChargeService.java
@After public void tearDown() throws Throwable { JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource); jdbcTemplate.execute("TRUNCATE TABLE CHARGE"); }
From source file:com.eheobo.samples.shiro.dao.BootstrapDataPopulator.java
public void afterPropertiesSet() throws Exception { if (isUserTableEmpty()) { //because we're using an in-memory hsqldb for the sample app, a new one will be created each time the //app starts, so insert the sample admin user at startup: JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource); jdbcTemplate.execute( "insert into roles(id, name, description) values (1, 'user', 'The default role given to all users.')"); jdbcTemplate.execute(//w w w . j a v a 2 s .c o m "insert into roles(id, name, description) values (2, 'admin', 'The administrator role only given to site admins')"); jdbcTemplate.execute("insert into roles_permissions(role_id, permissions) values (2, 'user:*')"); jdbcTemplate.execute( "insert into users(id,username,email,password) values (1, 'admin', 'sample@shiro.apache.org', '" + new Sha256Hash("admin").toHex() + "')"); jdbcTemplate.execute("insert into users_roles(users_id, roles_id) values (1, 2)"); } }
From source file:fm.lastify.config.LastifyFmWebappConfig.java
/** * Used to configure the in-memory HSQLDB database Remove this method if * different datasource is used//from w ww . ja v a 2s . c om * * @throws IOException */ @PostConstruct public void createDatabaseTable() throws IOException { Resource resource = new ClassPathResource( "org/springframework/social/connect/jdbc/JdbcUsersConnectionRepository.sql"); BufferedInputStream is = new BufferedInputStream(resource.getInputStream()); final char[] buffer = new char[0x10000]; StringBuilder out = new StringBuilder(); Reader in = new InputStreamReader(resource.getInputStream(), "UTF-8"); int read; do { read = in.read(buffer, 0, buffer.length); if (read > 0) { out.append(buffer, 0, read); } } while (read >= 0); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.execute(out.toString()); }
From source file:org.wte4j.examples.showcase.server.config.DatabaseConfigTest.java
@Test public void databaseIsIntializedTest() { JdbcTemplate template = new JdbcTemplate(ds); Set<String> wte4jTables = template.execute(new ConnectionCallback<Set<String>>() { @Override//from w w w .j av a2 s . c o m public Set<String> doInConnection(Connection con) throws SQLException, DataAccessException { Set<String> tableNames = new HashSet<String>(); ResultSet tableRs = con.getMetaData().getTables(null, null, null, new String[] { "TABLE" }); try { while (tableRs.next()) { tableNames.add(tableRs.getString("TABLE_NAME").toLowerCase()); } } finally { tableRs.close(); } return tableNames; } }); assertEquals(6, wte4jTables.size()); assertTrue(wte4jTables.contains("person")); assertTrue(wte4jTables.contains("purchase_order")); assertTrue(wte4jTables.contains("wte4j_template")); assertTrue(wte4jTables.contains("wte4j_template_properties")); assertTrue(wte4jTables.contains("wte4j_gen")); assertTrue(wte4jTables.contains("wte4j_template_content_mapping")); }
From source file:com.tmg.fuse.poc.DatabaseBean.java
public void destroy() throws Exception { JdbcTemplate jdbc = new JdbcTemplate(dataSource); try {//from ww w .ja v a 2 s.com jdbc.execute("drop table account"); } catch (Throwable e) { // ignore } try { jdbc.execute("drop sequence seq_xrefId"); } catch (Throwable e) { // ignore } }
From source file:com.emc.ecs.sync.service.MySQLDbService.java
@Override public void deleteDatabase() { JdbcTemplate template = createJdbcTemplate(); try {//from ww w. j a va 2 s. c o m template.execute("drop table " + getObjectsTableName()); } finally { close(template); } }