Differences between statement and preparestatement

Source: Internet
Author: User

See the following two program snippets: code fragment 1: String updatestring = "Update coffees set sales = 75" + "where cof_name like 'Colombian'"; stmt.exe cuteupdate (updatestring ); code fragment 2: preparedstatement updatesales = con. preparestatement ("Update coffees set sales =? Where cof_name like? "); Updatesales. setint (1, 75); updatesales. setstring (2, "Colombian"); updatesales.exe cuteupdate (); the difference between Segment 2 and segment 1 is that the latter uses the preparedstatement object, while the former is a common statement object. The preparedstatement object not only contains SQL statements, but also has been pre-compiled in most cases. When you need to execute the statement object multiple times, the preparedstatement object will greatly reduce the running time, of course, it also speeds up database access. Whether the preparedstatement object is selected depends on whether the SQL statements with the same syntax are executed multiple times, and the difference between the two statements is only the difference between variables. If it is executed only once, it should be no different from ordinary objects, and it does not reflect the superiority of its pre-compilation. Statement is used for general SQL query callablestatement. The Stored Procedure preparedstatement is used for pre-compiled SQL statements. It is created by the createstatement method with parameters and used to send simple SQL statements. Preparedstatement is created by the preparestatement method. The preparedstatement object is used to send an SQL statement with one or more input parameters. Callablestatement is created by the preparecall method to run the SQL storage program. The callablestatement object inherits the methods used to process the in parameter from the preparedstatement object, and also adds methods used to process the out and inout parameters.

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.