Why can preprocessing preparestatement in Java play a role in preventing SQL injection??!!

Source: Internet
Author: User

As we all know, in the Java JDBC, there is a preprocessing function, this function is a major advantage is to improve execution speed, especially the operation of the database multiple times, another advantage is to prevent SQL injection, strictly speaking, should be to prevent the vast majority of SQL injection.

The usage is shown on the following side:

String sql= "Update cz_zj_directpayment DP" + "Set Dp.projectid =?" where dp.payid=? "; try {preparedstatement pset_f = conn.preparestatement (sql);p set_f.setstring (1,inds[j]);p set_f.setstring (2,id);p set _f.executeupdate (sql_update);} catch (Exception e) {//e.printstacktrace (); Logger.error (E.message ());}


So why is it so handled to prevent SQL injection from improving security? In fact, because the SQL statement has been pre-compiled before the program is run, the SQL statement has been parsed, compiled and optimized by the database, and the corresponding execution plan is cached and allowed to be queried in the form of a parameterized database before the program is run for the first time. When the runtime dynamically passes parameters to preprarestatement, even if the parameter has a sensitive word such as or ' 1=1 ', the database will be treated as a property value of a field and not as a SQL instruction, so that SQL injection works!

Reprint please indicate-java my life (Chen Leixing) Source: http://blog.csdn.net/chenleixing/article/details/44024095

Why can preprocessing preparestatement in Java play a role in preventing SQL injection??!!

Related Article

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.