# Creating and Executing a SQL Query

Create a SQL file and run it against a given database instance.

You must create a project to store the SQL file that you want to create and assign the Apache Derby project nature to the project. You can then create a SQL file and associate it with a connection profile. Use the SQL Editor and Content Assist to add SQL commands. After you execute the query, you can view its results and modify the query, if necessary.

1. Select File > New > Project from the main menu bar.

   The Select a Wizard dialog opens. You must create an Eclipse project to contain your SQL file.

2. Select Java Project from the Wizards list box.
3. Click Next.

   The Create a Java Project wizard opens.

4. Type a name in the Project Name field and click Finish.

   The project appears in the Navigator. Now we can add the Apache Derby project nature to the project.

5. Right-click the project in the Navigator and select Apache Derby > Add Apace Derby nature.
   Adding the Apache Derby project nature provides the following to your project:
   - Adds jar files to the project's java build path.
   - Enables the Derby features for the project.

     Several new menu items now appear under the Apache Derby menu. The ij and sysinfo tools are available and the Apache Derby network server can be started and stopped using the menu.

   - Allows Apache Derby properties, for example, the port number the Network Server listens on and the value for derby.system.home to be set for the project.
6. Select File > New > Other from the main menu bar.

   The Select a Wizard dialog opens. You can now create a SQL file.

7. Expand SQL Development and select SQL File.

   The Create SQL File wizard opens.

8. Select the Connection profile type and Connection profile name.
9. Click Finish.

   The SQL editor opens.

10. Right-click in the editor and select Set Connection Info.

    The Select Profile for the Editor dialog opens.

11. Select the Connection profile type and Connection profile name and click OK.

    When this connection information is set, richer content assist for table and column names is enabled in the SQL editor.

12. Type the following SQL statement:

    `select * from SYS.SYSTABLES`

13. Right-click in the editor and select Execute All.

    The query results appear in the SQL Results view. The left pane displays the execution history. For each statement, including stored procedures, that you execute, an entry and Eclipse launch configuration is added. This allows you to quickly retest the execution using slightly different values and settings. You can rename or delete the launch configurations as needed.

Parent topic: Tutorial Overview
Previous topic: Running a Stored Procedure
Related concepts
Apache Derby
Content Assist
Related reference
Database Development Perspective