how we can shutdown hsqldb database in java

2019-04-12 13:12发布

问题:

i am using hsqldb as my database. i want whenerver my select query, update query execute it will shutdown a database. below is the method in which i need a code from which i can manually shutdown my database.

private void insertInitData(BasicDataSource dataSource, int lmexAdapterId, int lmsId) {
    try {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        String lmexPostParam_id = UUID.randomUUID().toString();
        String inertQuery = "Insert into lmex_post_param (lmex_post_param_id, param_name, param_value) values (?,?,?)";
        String[] baseUrlParam = { lmexPostParam_id, "base_url", lmexPostingBaseUrl };
        jdbcTemplate.update(inertQuery, baseUrlParam);
        String lmexPostParamId2 = UUID.randomUUID().toString();
        String[] postServiceParam = { lmexPostParamId2, "post_service_url", lmexPostingPostServiceUrl };
        jdbcTemplate.update(inertQuery, postServiceParam);
        String lmexPostParamId3 = UUID.randomUUID().toString();
        String[] lmsIdParam = { lmexPostParamId3, "lms_id", lmsId+"" };
        jdbcTemplate.update(inertQuery, lmsIdParam);
        String lmexPostParamId4 = UUID.randomUUID().toString();
        String[] adapterIdParam = { lmexPostParamId4, "adapter_id", lmexAdapterId+"" };
        jdbcTemplate.update(inertQuery, adapterIdParam);
        //shutdown database by code
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

the code must be replace in the place of comment "shutdown database by code".

help me

Thank you in advance

回答1:

For example:

jdbcTemplate.execute("SHUTDOWN");


回答2:

use the below code to shutdown your database using java code.

jdbcTemplate.execute("SHUTDOWN");

it works