HSQLDB run from code connect from client

Dmitry
2011-10-20
2014-01-19
  • Dmitry
    Dmitry
    2011-10-20

    I have a problem. I need to create Server of HSQLDB from my code, run it and connect from another application (for e.x. by runManagerSwing.bat) Here are my code

    HsqlProperties p = new HsqlProperties();
            p.setProperty("server.database.0", "file:./db/idt_simulatordb");
            p.setProperty("server.dbname.0", "idt_simulatordb");
            p.setProperty("server.port", "9001");
            Server server2 = new Server();
            server2.setProperties(p);
        // I even can connect to my server from the same application
        Connection conn = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:9001   /idt_simulatordb", "sa", "");
                Statement st = conn.createStatement();    // statements
                String expression1 = "DROP SCHEMA IF EXISTS simulators CASCADE;\n";
                String expression2 = "CREATE SCHEMA SIMULATORS AUTHORIZATION SA;";
                String expression3 = "CREATE TABLE SIMULATORS.dirtyhack();";
                st.executeUpdate(expression1);    // run the query
                st.executeUpdate(expression2);    // run the query
                st.executeUpdate(expression3);    // run the query
    //
                st.close();
                conn.close();
            server2.start();
    server2.shutdownWithCatalogs(Database.CLOSEMODE_NORMAL);
    

    But when I put breakpoint after server run and try to connect to my server from runManagerSwing I got timeout error.

    But if I launch server from bat-file, then everething ok. How to solve my problem. Isuppose thaat I have to use MainInvoker but I don't know how to pass argument and how to shutwown server after all. thanx

     
  • Blaine Simpson
    Blaine Simpson
    2011-10-20

    You aren't going to be able to connect to any service before you start the service. This is what is attempted by

        ...DriverManager.getConnection(...)
        ... server2.start();
    

    But this sample code doesn't even attempt to do anything like your stated goal- to run a Server in one JVM and a client in another JVM. Separate out the two parts (server part and client part) into separate classes loaded by separate Java mains. MainInvoker is for when you want to use the main(String) methods from more than one class in the same JVM. That is nothing like your use case.

    (Post updated just to fix my attempted wikitext formatting)

     
  • Blaine Simpson
    Blaine Simpson
    2011-10-20

    If you want help, it would be better to use the forum labeled "Help" in the future.  If somebody wants to provide help, or if other people want to search to see how you have been helped, that is where they will look.