A new database feature in NetBeans 6.5 is the ability to save and
reuse SQL statements that have been executed. A dialog listing SQL
statements along with the date executed can be opened from the SQL
Editor by right-clicking within the editor and choosing SQL History or
clicking an image button for SQL History in the SQL Editor toolbar.
To reuse previously executed SQL statements, in the SQL History
dialog, select an SQL statement then click the Insert button, or
double-click on the SQL History. SQL is inserted at the location of the
editor cursor.
In order to fit the SQL within the width allocated in the dialog,
SQL has been truncated. To see the entire SQL, mouse over the SQL and a
tooltip opens displaying the entire SQL statement.
Initially, the order of SQL displayed is descending by date, so the
most recently executed statement appears first. However, if there are
many statements listed, then the order can be changed.
To reverse the order by date, click the header of the Date Executed column. Or, to sort the SQL alphabetically, click on the SQL Executed column header.
To search for a string in the list of SQL, type the string in the Matching SQL text field.
To list only the SQL executed only for a given database connection, select the connection from the Connection dropdown.
If you want to limit the number of SQL statements to save, enter a
number (less than or equal to 10,000) and click Apply. To remove all
statements set the limit to 0, click Apply. Remember to reset the
number to a number greater than 0 so statements can be saved again.
Next, I'll use the MySQL database and show how to create a Trip table in the Sakila database.
Requirements
- MySQL installed and started
- Sakila plugin installed
Steps
- We'll create the Sakila sample database.
- In Services, right-click on the MySQL node and choose create table. In the Create Table dialog, select sakila.
- Repeat to create the travel database
- In Services, select the Travel connection, jdbc:mysql://localhost:3306/travel right-click and choose Execute Command - SQL Editor opens
- Open SQL History by right-clicking on the SQL Editor and choose SQL History
- The SQL History dialog lists the SQL that was executed to create the sample databases and insert records. (for screenshot, see attached file, after_creating_tables.png)
- Next we'll add the trip table from the travel database to the sakila database
- In SQL History, select the Connection dropdown and choose the connection for Travel
- In the Matching SQL textfield, mis-type the string, creeate
- Edit the match string. Position the cursor at the end of the string, type the backspace key and correct the spelling to create table travel.trip
- Select the create statement for the Trip table then click the
Insert button. SQL is inserted in the SQL Editor at the location of the
cursor.
- Replace the string in the Matching SQL textfield with, INSERT INTO TRAVEL.TRIP . Note, the match string is case insensitive.

- Select one insert statement (for the trip table), then click
the Insert button or double-click. Repeat inserting a few more
statements
- Close SQL History
- From the main menu choose Edit->Replace and replace all instances of the string, travel with sakila
Screenshot
- In the SQL Editor, choose the connection for Sakila, jdbc:mysql://localhost:3306/sakila , then click the Green arrow to execute the SQL inserted.
- To see that a table was added, in Services, expand the sakila
connection right-click on the Tables node, choose Refresh and see that
the trip table has been created.
Next, let's how how to change the view of SQL listed.
- Reopen SQL History. You can see the statements that were just executed to create the sakila.trip table
- To list statements alphabetically, click on the SQL Executed header. Note, the first sort is reverse-alphabetical.
- Clicking the SQL Executed header again will sort the SQL in alphabetical order.
- And to list the statements by date, in reverse order, with the latest date executed appearing as the first item, click on the Date Executed header
- Next, let's reset SQL History using the Number of SQL statements to Save field by setting the value to 5 and click Apply.
- Close SQL History
- Try to execute a statement, for the MySQL sakila connection, jdbc:mysql://localhost:3306/sakila, right-click and choose Execute Statement
- In the SQL Editor, type, select * from sakila.trip
Look for usability improvements in the 6.5 patch 1 release. Here's a list of fixes going into Patch1:
- Cannot remove database table column from action
- SQL History: vertical resize doesn't resize all comp
- SQL History: only one item inserted into document
- SQL History: if running NB in multiple locales the history file cannot be parsed
and in
Patch 2
- SQL History: Dialog shouldn't be modal