Application of the Statement interface (there is an injection risk of SQL statements)

Source: Internet
Author: User

Enables simple sign-in functionality

Import Java.sql.connection;import java.sql.drivermanager;import java.sql.resultset;import java.sql.SQLException;    Import Java.sql.statement;public class Jdbcfindall {private static final String jdbcname= "Com.mysql.jdbc.Driver";    private static final String url= "jdbc:mysql://127.0.0.1:3306/emp_dept";    private static final String user= "root";    private static final String password= "123456"; /* * A Class (Drivermaneger) four interfaces (Connection, PreparedStatement, ResultSet, Statement) * */public static void main (Stri        Ng[] (args) {//TODO auto-generated method stub Connection conn=null;            try {class.forname (jdbcname);            Conn=drivermanager.getconnection (URL, user, password); Logon action String usr= "Aaawfwfwfwfw ' or 1 #";                        The risk of SQL injection is String pwd= "334343343434";            String sql= "Select id,usr,pwd from user where usr= '" +usr+ "' and pwd= '" +pwd+ "'"; Statement st=conn.createstatement();            ResultSet rs=st.executequery (SQL); if (Rs.next ()) {System.out.println ("Login Successful! Go to the main page!            "); }else{System.out.println ("User name or password is wrong! Login failed!            ");        }} catch (Exception e) {e.printstacktrace ();            } finally {try {conn.close ();            } catch (SQLException e) {//TODO auto-generated catch block E.printstacktrace (); }        }    }}

There is a risk of SQL injection in the following red section

The SQL statements appear as:

Query results such as: (Show all the results of the query)

In this case, the user does not know the user name and password in the case of easy login success. So do not use the statement interface, with the PreparedStatement interface.

Application of the Statement interface (there is an injection risk of SQL statements) (RPM)

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.