Search in sources :

Example 1 with DatabasePopulator

use of org.springframework.jdbc.datasource.init.DatabasePopulator in project leopard by tanhaichao.

the class DomainWhiteListConfigImpl method createTable.

protected void createTable() {
    StringBuilder sb = new StringBuilder();
    sb.append("CREATE TABLE  if not exists `leopard_domainwhitelist` (");
    sb.append("`domain` varchar(50) NOT NULL DEFAULT '',");
    sb.append("`username` varchar(50) NOT NULL DEFAULT '',");
    sb.append("`posttime` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',");
    sb.append("`comment` varchar(255) NOT NULL DEFAULT '',");
    sb.append("PRIMARY KEY (`domain`)");
    sb.append(");");
    String sql = sb.toString();
    Resource scripts = new ByteArrayResource(sql.getBytes());
    DatabasePopulator populator = new ResourceDatabasePopulator(scripts);
    try {
        DatabasePopulatorUtils.execute(populator, jdbcTemplate.getDataSource());
    } catch (ScriptStatementFailedException e) {
    }
}
Also used : ResourceDatabasePopulator(org.springframework.jdbc.datasource.init.ResourceDatabasePopulator) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ResourceDatabasePopulator(org.springframework.jdbc.datasource.init.ResourceDatabasePopulator) DatabasePopulator(org.springframework.jdbc.datasource.init.DatabasePopulator) ScriptStatementFailedException(org.springframework.jdbc.datasource.init.ScriptStatementFailedException)

Aggregations

ByteArrayResource (org.springframework.core.io.ByteArrayResource)1 Resource (org.springframework.core.io.Resource)1 DatabasePopulator (org.springframework.jdbc.datasource.init.DatabasePopulator)1 ResourceDatabasePopulator (org.springframework.jdbc.datasource.init.ResourceDatabasePopulator)1 ScriptStatementFailedException (org.springframework.jdbc.datasource.init.ScriptStatementFailedException)1