# PlanExporter example

This example shows the steps that you must follow in order to use the `PlanExporter` tool.

1. Move to the directory where your database was created.
2. Run the `ij` tool:

       java org.apache.derby.tools.ij

3. Create a connection to the database:

       CONNECT 'jdbc:derby:myDb;create=false';

   Note: You can use a Derby client/server database as well.
4. Use XPLAIN styles:

       CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1);
       CALL SYSCS_UTIL.SYSCS_SET_XPLAIN_SCHEMA('MY_SCHEMA');
       select * from my_table;
       CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(0);
       CALL SYSCS_UTIL.SYSCS_SET_XPLAIN_SCHEMA('');

5. Obtain the `stmt_id` of the query:

       select stmt_text, stmt_id from MY_SCHEMA.SYSXPLAIN_STATEMENTS;
       exit;

   Now find the `stmt_id` of the executed query in the displayed results and note it down. It looks something like this:

       9ac8804c-0129-cc31-ca9a-00000047f1e8

6. Run the `PlanExporter` tool in the same location:

       java org.apache.derby.tools.PlanExporter jdbc:derby:myDb MY_SCHEMA
           9ac8804c-0129-cc31-ca9a-00000047f1e8 -html plain_html;

   This command uses the default style sheet provided with Derby, and the HTML file will be generated at the same location, since the command does not specify a different path. The name of the HTML file generated is `plain_html.html`.

Parent topic: PlanExporter
Related concepts
Using PlanExporter
Related reference
PlanExporter XML format