美文网首页
【Java】【JDBC】使用preparedStatement预

【Java】【JDBC】使用preparedStatement预

作者: JerichoPH | 来源:发表于2017-04-08 09:53 被阅读49次

    使用preparedStatement预编译解决SQL注入

    /**
     * 执行登陆
     *
     * @return boolean
     * @throws Exception ?
     */
    public boolean login() throws Exception {
        Connection connection = MyDatabase.getConn();
        PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM user WHERE signin_name=?");
        preparedStatement.setString(1, signinName);
        ResultSet resultSet = preparedStatement.executeQuery();
        
        String pwd = "";
        while (resultSet.next()) {
            pwd = resultSet.getString("pwd");
        }
        MyDatabase.kill(connection, preparedStatement, resultSet);
        return pwd.equals(MyString.Md5(this.pwd));
    }
    

    相关文章

      网友评论

          本文标题:【Java】【JDBC】使用preparedStatement预

          本文链接:https://www.haomeiwen.com/subject/gbclattx.html