# Using PlanExporter

Before you run the `PlanExporter` tool, make sure that your classpath contains the Derby jar files, including `derbytools.jar`/

Before you run the `PlanExporter` tool, you must capture the `stmt_id` of the query you have executed from `SYSXPLAIN_STATEMENTS system table`. To do so, follow these steps:

1. Use XPLAIN styles to capture the runtime statistics.

   Refer to "SYSCS_UTIL.SYSCS_SET_XPLAIN_SCHEMA system procedure" in the Derby Reference Manual to see how to do this.

   Note: You must remember the `schema_name`.
2. Query the SYSXPLAIN_STATEMENTS system table to obtain the `stmt_id` of the query you have executed.

   Refer to "SYSXPLAIN_STATEMENTS system table" in the Derby Reference Manual for information about the SYSXPLAIN_STATEMENTS system table.

You can run the tool as follows in the directory where your database is located (all on one line).

    java org.apache.derby.tools.PlanExporter derby_connection_URL
       schema_name stmt_id options

The options can be passed according to your requirements. Consider the following possible scenarios:

- To generate an XML file of the query plan, specify the following option:

      -xml path

  The path can be either absolute or relative. If the root filename does not have a suffix, the tool appends `.xml`.

- To generate a plain HTML file of the query plan, you can use the default simple style sheet provided with Derby. Specify the following option:

      -html path

  If the root filename does not have a suffix, the tool appends `.html`.

  To generate the XML file as well, specify the following options:

      -xml path -html path

  To use a different style sheet that does not contain any Javascript functions, specify the following options:

      -xsl path -html path

  To generate the XML file as well, specify the following options:

      -xml path -xsl path -html path

- To generate an advanced view of the query plan, you can use advanced XSL style sheets provided with Derby inside `derbytools.jar/org/apache/derby/impl/tools/planexporter/resources/`, or you can specify a style sheet you created. To do this, specify the following options:

      -adv -xsl fileName -xml path

  Note:
  - Before you use the `-adv` feature, you must copy the advanced XSL style sheet into the current directory. Thus, you must specify only the name of the style sheet, not the path.
  - Generating HTML is not supported when you use the `-adv` option of the `PlanExporter` tool. But if you open the generated XML file in a web browser, the browser will do the necessary transformation.

Parent topic: PlanExporter
Related reference
PlanExporter XML format
PlanExporter example