Search in sources :

Example 1 with ScriptStatementFailedException

use of org.springframework.jdbc.datasource.init.ScriptStatementFailedException in project spring-framework by spring-projects.

the class EmbeddedDatabaseBuilderTests method createSameSchemaTwiceWithoutUniqueDbNames.

@Test
public void createSameSchemaTwiceWithoutUniqueDbNames() throws Exception {
    EmbeddedDatabase db1 = //
    new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())).addScripts("db-schema-without-dropping.sql").build();
    try {
        //
        new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())).addScripts("db-schema-without-dropping.sql").build();
        fail("Should have thrown a ScriptStatementFailedException");
    } catch (ScriptStatementFailedException e) {
    // expected
    } finally {
        db1.shutdown();
    }
}
Also used : ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) ScriptStatementFailedException(org.springframework.jdbc.datasource.init.ScriptStatementFailedException) Test(org.junit.Test)

Example 2 with ScriptStatementFailedException

use of org.springframework.jdbc.datasource.init.ScriptStatementFailedException 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

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