Use of placeholders in Jfinal database operation statements

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.