Ejemplo n.º 1
0
  private void runHsqldbServer(final String fileName, final int port, final char[] password) {
    org.hsqldb.server.Server hsqlServer = new org.hsqldb.server.Server();

    hsqlServer.setPort(port);
    hsqlServer.setDatabaseName(0, "jgnash"); // the alias
    hsqlServer.setDatabasePath(0, "file:" + FileUtils.stripFileExtension(fileName));

    hsqlServer.start();

    // Start the message server and engine, this should block until closed
    if (!run(DataStoreType.HSQL_DATABASE, fileName, port, password)) {
      Logger.getLogger(JpaNetworkServer.class.getName()).severe("Failed to start the server");
    }

    hsqlServer.stop();
  }
Ejemplo n.º 2
0
  /*
   * 启动数据库服务
   */
  public static boolean startHSQL() {
    if (mode == SERVER_MODE) {
      Server server = new Server(); // 它可是hsqldb.jar里面的类啊。
      server.setDatabaseName(0, DB_NAME);
      server.setDatabasePath(0, DB_PATH + DB_NAME);
      server.setPort(PORT);
      server.setSilent(true);
      server.start(); // 自动多线程运行
      System.out.println("hsqldb started...");
    } else if (mode == STAND_ALONE_MODE) {
      // standalone模式,打开连接就同时启动数据库,所以这里可以什么都不做
    }

    try {
      Thread.sleep(1000); // 等待Server启动
    } catch (InterruptedException e) {
    }
    return true;
  }