Well, I need to create hsqldb in server mode and connect to this server from another client (f.e. from runManagerSwing.bat).
Here are my code:
public static Server server = new Server();
public static void main(String[] args) throws IOException, ServerAcl.AclFormatException, SQLException {
HsqlProperties p = new HsqlProperties();
p.setProperty("server.database.0", "file:./db/myHsqlDb");
p.setProperty("server.dbname.0", "idt_simulatordb");
p.setProperty("server.port", "9001");
server.setProperties(p);
server.setSilent(false);
server.setTrace(true);
server.start();
(1) Connection conn = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:9001/idt_simulatordb", "sa", "");
Statement st = conn.createStatement();
String expression1 = "DROP SCHEMA IF EXISTS simulators CASCADE;\n";
String expression2 = "CREATE SCHEMA SIMULATORS AUTHORIZATION SA;";
String expression3 = "CREATE TABLE SIMULATORS.dirtyhack();";
String expression4 = "DROP SCHEMA IF EXISTS myschema CASCADE;\n";
String expression5 = "CREATE SCHEMA myschema AUTHORIZATION SA;";
st.executeUpdate(expression1);
st.executeUpdate(expression2);
st.executeUpdate(expression3);
st.executeUpdate(expression4);
st.executeUpdate(expression5);
st.close();
conn.close();
(2)server.shutdown();
}
To check out that my server is fine I add line (1). And it’s really ok. But I want to connect from another tool. To do so I put break point before (2) and start client runManagerSwing.bat.
The client succsessfully finds server but suspend. Sometimes it wakeup if I make several step between line (1) and (2).
- Why does it happen? Maybe I have to launch server from another thread? How to do so?
- And second question. I want to clear up all hsqldb files after shutdown (even .properties and .script). Are there any preferences to do so or I have to delete it manually?
p.s. sorry for my english
Your program uses server.start() which starts the server from a separate thread. This is how you can connect to it after server.start() is executed. If it was the same thread, the code you marked with (1) would not execute.
If you remove the server.shutdown() line at the end and do not put a breakpoint, then you can connect from DatabaseManagerSwing. When you want to shutdown the server, use DatabaseManagerSwing and execute the SQL statement “SHUTDOWN”.
When you use a breakpoint in an IDE, it may suspend execution of other threads as well.
There is no way to delete the database files automatically. The next version 2.2.6 will have a static mathod as a utility to delete a set of database files.