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??!!