<< Click to Display Table of Contents >> Parameter Component - Use script |
![]() ![]() ![]() |
Both the form parameter component and other parameter components can submit data guidance database. This section will introduce you to the method for submitting data in text, list, and combobox parameters to the database.
Currently this product supports data submission to databases: SQLSERVER, MYSQL, DB2, ORACLE, DERBY, POSTGRESQL. There are two ways to submit data, one is submitted through the interface, and the other is submitted through a script. Both of these methods require the use of a submit control. When the submit control is clicked, the data is submitted to the database.
❖Submitted interface
1. Add a submit component
The components that can be used to submit include: Submit component, Image component, Text component. Take the submit component as an example.
Drag the submit component to the dashboard edit area in the dashboard right panel - component.
2. Set the submission properties
The "On Commit" window is present in the submit component's script dialog. The submitted script can be edited in this window.
Parametric component submission scripts should be set under the dashboard folder. The parameter component is submitted as follows:
can submit insert, update, remove data columns;
As shown in the following figure, you can submit the data column inserted in the parameter component after setting:
After the success of submit component and the form parameter component to the database, the corresponding result feedback prompt will pop up.
❖Script submission
➢For example, you need to submit the data of student basic information to the database through the interface, and design the interface as shown in the following figure:
First of all, the components that need to be created are: Name input box "Text input box 1", Age input box: "Text input box 2", and Sex selection box: "Single Seletion Combobox 1" You also need to create a text component as Submit button. Among them, Single Seletion Combobox 1 needs to be bound to the stuSex column, and then in the submitting component text, edit the following script to submit it.
The script reads as follows:
var conn = null;
try {
conn = createConnection(SQL, "Test/sql database / student ");
/*
Create a database connection through an SQL query, where SQL represents the query type, "Test/sql database / student" represents the path of the query, or you can create a database connection through a data source, as can be written as conn = createConnection(CONNECTION, "test/ Data Source/ SQLSERVER_ data source")
*/
var stuName = new Array();// Define the stuName array
var stuAge = new Array();// Define the stuAge array
var stuSex = new Array();// Define the stuSex array
stuName = Text Parameter 1.getSelectedObjects();// Get stuName value
stuAge = Text Parameter 2.getSelectedObjects();// Get stuAge value
stuSex = Single Seletion Combobox1.getSelectedObjects();// Get stuSex value
var pstmt = conn.prepareStatement("insert into stu (stuName, stuAge, stuSex) values (?,?,?)");
/*
Insert data into the database, where stu is the name of the table to be inserted into the database, stuName, stuAge, and stuSex are the columns in the table stu, corresponding to the question marks that follow
*/
pstmt.setString (1,stuName[0]);
pstmt.setInt (2, stuAge[0]);
pstmt.setString (3, stuSex[0]);
pstmt.executeUpdate();
conn.commit();
}
// Insert the obtained stuName, stuAge, stuSex values into the database and update the database
catch(e){
try {
if(conn != null) {
conn.rollback();
}
}
catch(e1) {
}
debug("Update DataBase Error: " + e);
}
finally {
if(conn != null) {
try {
conn.close();
}
catch(e2) {
}
}
}