HSQLDB: How to truncate the database after testing?

633 Views Asked by At

I have been trying to create a testing database and clearing it after testing, but it is not getting deleted. And hence throwing an exception- object name already exists: USER in Statement... Here's my code in BeforeClass and AfterClass annotations-

@BeforeClass
public static void initialize() throws Exception {
    databaseTester = new JdbcDatabaseTester(org.hsqldb.jdbcDriver.class
    .getName(), "jdbc:hsqldb:file:testdatabase", "sa", "");
    createTables(databaseTester.getConnection().getConnection());

    String inputXml = "<dataset>" 

            +"<user UID=\"9999\" NAME=\"XYZ\" PHONE=\"9999999999\" PASSWORD=\"qwerty\" SALT_KEY=\"0\" DEVICE_UUID=\"99999\" LID=\"1\" USER_TYPE=\"1\" OTP_STATUS=\"A\" STATUS=\"0\" POSTAL_ADDRESS=\"0\" CREATE_USER=\"0\" UPDATE_USER=\"0\" />"
            +"<user UID=\"9998\" NAME=\"ABC\" PHONE=\"9999999998\" PASSWORD=\"qwerty\" SALT_KEY=\"0\" DEVICE_UUID=\"99998\" LID=\"1\" USER_TYPE=\"1\" OTP_STATUS=\"A\" STATUS=\"0\" POSTAL_ADDRESS=\"0\" CREATE_USER=\"0\" UPDATE_USER=\"0\" />"
            +"<user_category  UCID=\"9999\" UID=\"0\" DEVICE_UUID=\"77777\" CID=\"7\" CREATE_USER=\"0\" UPDATE_USER=\"0\" />" 

                    + "</dataset>";

    IDataSet dataSet = new FlatXmlDataSetBuilder().build(new StringReader(inputXml));
    databaseTester.setDataSet(dataSet);
    databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT);
    databaseTester.setTearDownOperation(DatabaseOperation.DELETE_ALL);
    databaseTester.onSetup();

}

@AfterClass
public static void cleanUp() throws Exception {
     databaseTester.onTearDown();
     databaseTester = null;
}

It's not getting deleted automatically, instead I need to manually delete the content of the text file created after the test.

1

There are 1 best solutions below

0
On

Run the statement:

DROP SCHEMA PUBLIC CASCADE

See the Guide:

http://hsqldb.org/doc/2.0/guide/databaseobjects-chapt.html#dbc_schemas_schema_objects