Beispiel #1
0
  @Override
  public int parser(String string) throws SQLException {

    int rval = 0;
    if (string.trim().length() == 0 || string.isEmpty()) return rval;
    string = string.toLowerCase();

    if (string.equals("help")) {
      this.help();
      rval = 1;
    } else if (string.equals("exit")) {
      this.print("");
      this.print("Closing connection...");
      connectionManager.close();
      rval = -1;
    } else if (string.equals("list")) {
      print(
          String.format(
              "\nList of tables in database: %s, on the server: %s:%s",
              configReader.getDatabaseName(),
              configReader.getServername(),
              configReader.getPortNumber()));
      int index = 1;
      for (String s : dbController.tableList()) {
        print(String.valueOf(index++) + "." + s);
      }
      rval = 1;
    } else if (string.startsWith("select")) {
      print(String.format("\nResult: \"%s\"", string));
      Table table = new Table(dbController, string);

      for (List<String> row : table.getTable()) {
        System.out.println(row.toString());
      }
      rval = 1;

    } else {
      dbController.executeCommand(string);
      print(String.format("%s command was successfully!!!", string.split(" ")[0]));
      rval = 1;
    }
    return rval;
  }
Beispiel #2
0
  public InformerImpl(ConnectionManager connectionManager, ConfigReader configReader)
      throws SQLException, IOException {
    this.connectionManager = connectionManager;
    this.configReader = configReader;
    connection = connectionManager.connect();
    dbController = new DbControllerImpl(connection);

    if (this.connectionManager == null) {
      System.out.println(connectionManager);
      System.out.println(this.connectionManager);
    }

    if (this.configReader == null) {
      System.out.println(this.configReader.toString());
      System.out.println(configReader);
    }
    if (connection == null) {
      System.out.println(connection);
    }
    if (dbController == null) {
      System.out.println(dbController);
    }
    print("Type \"help\" for command list or type command: ");
  }