Add Data to Database

A common way to insert information into a database is to execute a SQL query after the user presses a button. The button can run a script to collect the information it needs to go into the database and then execute a SQL INSERT statement.

Suppose you had a window that had three components and a button. A script executed on the button's actionPerformed event handler would collect the relevant properties and insert them into a database. Here is some example code:

Insert into database
firstName = event.source.parent.getComponent('FirstName').text
lastName = event.source.parent.getComponent('LastName').text
age = event.source.parent.getComponent('Age').intValue
 
query = "INSERT INTO people (FirstName, LastName, Age) VALUES (?,?,?)"
args = [firstName, lastName, age]
system.db.runPrepUpdate(query, args)

This code assumes that there is a table that exist with the correct column names. Also, it probably has an auto-incrementing ID column as many tables do.