Thu, 16 Mar 2023 20:06:09 +0200, /Stanimir Stamenkov/:

I'm not finding destroy=true attribute but a drop=true one:

  * Setting attributes for the database connection URL <https://db.apache.org/derby/docs/10.16/ref/rrefattrib24612.html> (Derby Reference Manual)

that is specific for in-memory databases.  destroy=true is likely doing nothing but have you logged any possible exception in the catch blocks to see if Derby isn't actually failing the operation altogether?

You may use drop=true with a specific in-memory database:

    try {
        DriverManager.getConnection(
                "jdbc:derby:memory:TestDB;drop=true");
    } catch (SQLException e) {
        if (e.getSQLState().equals("08006")) {
            // Database 'TestDB' dropped.
            System.out.println(e.getMessage());
        } else {
            throw e; // unexpected
        }
    }

You may use shutdown=true with any embedded database (in-memory or persisted):

    try {
        DriverManager.getConnection(
                "jdbc:derby:memory:TestDB;shutdown=true");
    } catch (SQLException e) {
        if (e.getSQLState().equals("08006")) {
            // Database 'TestDB' shutdown.
            System.out.println(e.getMessage());
        } else {
            throw e; // unexpected
        }
    }

You may shut the complete engine down:

    try {
        DriverManager.getConnection(
                "jdbc:derby:;shutdown=true");
    } catch (SQLException e) {
        if (e.getSQLState().equals("XJ015")) {
            // Derby engine shutdown.
            System.out.println(e.getMessage());
        } else {
            throw e; // unexpected
        }
    }

You may want deregister=false with shutdown=true:

    try {
        DriverManager.getConnection(
                "jdbc:derby:;shutdown=true;deregister=false");
    } catch (SQLException e) {
        if (e.getSQLState().equals("XJ015")) {
            // Derby engine shutdown.
            System.out.println(e.getMessage());
        } else {
            throw e; // unexpected
        }
    }

--
Stanimir

Reply via email to