Example - Inserting Values
Say we have a table called machines in a database with three columns: an id column, a machine_name column, and an area_number column. We can build a query and a script that will insert the data into the database:
- Create a new Named Query. Set up security to fit your needs and name it appropriately. For more information on creating Named Queries, see Using Named Queries - Example.
- Set the Query Type to Update Query.
- Create two Value type Parameters.
- The first will be a string data type and will be for the name of the machine so it can be called machineName.
- The second will be an Int2 data type and will be for the area number so it can be called areaNumber.
Create the insert query.
On a Main Window, add a Button component, a Text Field component, and a Dropdown Component.
On the Dropdown's Data property, create a dataset that looks like this:
Value Label 1 Area 1 2 Area 2 3 Area 3
- On the Button's Text property, change the value to something like "Submit"
- Right Click on the Button and select Scripting. Navigate to the Script Editor tab on the actionPerformed Event Handler.
Copy in this script, which will pull in the value from the Dropdown and the Text Field and insert them into the table using the Named Query we built in step 1.
- Test it out by selecting an area, entering in a machine name, and clicking the submit button. You can check out the new rows using the Database Query Browser to select the values from that table.