标签:creates uname query connect mysq void null mysql cep
SQL注入问题
package space.urbeautiful.utils; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Login { public static void main(String[] args) { log("‘ or ‘ 1=1","‘ or ‘1=1"); } public static void log(String username,String password){ Connection conn = null; Statement stat = null; ResultSet rs = null; try { conn = JdbcUtils.getConn(); stat = conn.createStatement(); String sql = "select * from userlogin where uname = ‘"+username+"‘ and password = ‘"+password+"‘"; rs = stat.executeQuery(sql); while(rs.next()){ System.out.println(rs.getString("uname")); System.out.println(rs.getString("password")); } } catch (SQLException e) { e.printStackTrace(); }finally{ JdbcUtils.release(conn,stat,rs); } } }
解决的办法就是不适用Statement 使用PrepareStatement
标签:creates uname query connect mysq void null mysql cep
原文地址:https://www.cnblogs.com/jzspace/p/13053000.html