Advantages of placeholders:
1. Increase the readability of SQL code
2. Placeholder can be pre-compiled to improve execution efficiency
3. Preventing SQL injection
4. The purpose of the placeholder is to bind the variable, which can reduce the hard parsing of data sql, so the execution efficiency will improve a lot
Suppose you want to update the payroll for employees with IDs from 1 to 10000 to $150.00,
Do not use bound variables:
Sql.executequery ("UPDATE employees SET Salay = 150.00 WHERE id = 1");
Sql.executequery ("UPDATE employees SET Salay = 150.00 WHERE id = 2");
Sql.executequery ("UPDATE employees SET Salay = 150.00 WHERE id = 3");
Sql.executequery ("UPDATE employees SET Salay = 150.00 WHERE id = 4");
....
Sql.executequery ("UPDATE employees SET Salay = 150.00 WHERE id = 10000");
To use a binding variable:
UPDATE employees SET Salay =? WHERE id =? "
The difference is that instead of binding a variable, it is equivalent to parsing and executing a 1w SQL statement repeatedly. With a binding variable, the parse SQL statement is used only once, followed by a 9,999-second reuse of the execution plan that was generated for the first time. Obviously, the latter will be more efficient.
Use of placeholders in Jfinal database operation statements