会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132440个问题
Python 全系列/第十五阶段:Python 爬虫开发/爬虫基础(旧) 12001楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/商城官网项目 12002楼
JAVA 全系列/第五阶段:JavaWeb开发/Ajax技术详解(旧) 12004楼
Python 全系列/第五阶段:数据库编程/MySQL数据库的使用 12005楼

from tkinter import *
from tkinter import messagebox


class Application(Frame):
    def __init__(self,master):
        Frame.__init__(self,master)
        self.master = master
        self.pack()
        self.creatWidget()

    def creatWidget(self):
        # 多行文本
        self.w1 = Text(root, width=40,height=12,bg='gray')
        self.w1.pack()
        self.w1.insert(1.0,'0123456789\nabcdefg')
        self.w1.insert(2.3, "锄禾日当午, 汗滴禾下土。 谁知盘中餐, 粒粒皆辛苦\n")

        # 重复插入文本按钮
        self.btn01 = Button(self,text='重复插入文本',command=self.insertText)
        self.btn01.pack(side='left')

        # 返回文本按钮
        self.btn02 = Button(self,text='返回文本',command=self.returnText)
        self.btn02.pack(side='left')

        # 添加图片按钮
        self.btn03 = Button(self,text='添加图片',command=self.addImage)
        self.btn03.pack(side='left')

        # 添加组件
        self.btn04 = Button(self,text='添加组件',command=self.addWidget)
        self.btn04.pack(side='left')


    def insertText(self):
        self.w1.insert(INSERT,'chenhaobang')
        self.w1.insert(END,'[bang]')
        self.w1.insert(1.8,'chen')

    def returnText(self):
        print(self.w1.get(1.2,1.6))

    def addImage(self):
        global photo
        photo = PhotoImage(file=r'D:\Python_Test\imgs_GUI\logo.gif')
        self.w1.image_create(END,image=photo)

    def addWidget(self):
        b1 = Button(self.w1, text='爱尚学堂')
        self.w1.window_create(INSERT, window=b1)

if __name__ == '__main__':
    root =Tk()
    root.geometry('500x400+200+200')
    app = Application(root)
    root.mainloop()

老师,你好

多次按下“添加图片”按钮后,只显示一张图片,这是什么原因呢

image.png


Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 12006楼
Python 全系列/第二十三阶段:人工智能基础_机器学习理论和实战(旧)/SVM支持向量机算法 12007楼
Python 全系列/第一阶段:Python入门/Python入门(动画版) 12008楼
JAVA 全系列/第十二阶段:Spring Cloud Alibaba技术栈/Dubbo 12010楼
Python 全系列/第四阶段:函数式编程和核心特性/内存管理(旧) 12012楼

老师您好,可以麻烦帮我看一下吗,使用preparedStatement还是能全部查到数据库信息,这是什么原因导致的?谢谢!

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * SQL注入测试类
 */
public class SqlInjectTest {
    /**
     * 体现sql注入
     */
    public void sqlInTest(String username,int userage){
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try{
            //获取连接
            connection = JdbcUtils.getConnection();
            //创建Statement对象
            statement = connection.createStatement();
            //定义sql语句
            String sql = "select * from users where username = '"+username+"' and userage = "+userage;
            System.out.println(sql);

            //执行sql语句
            resultSet = statement.executeQuery(sql);
            //处理结果集
            while(resultSet.next()){
                int userid = resultSet.getInt("userid");
                String name = resultSet.getString("username");
                int age = resultSet.getInt("userage");
                System.out.println(userid+" "+name+" "+age);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            JdbcUtils.CloseResource(resultSet,statement,connection);
        }
    }


    public void noSqlInject(String username,int userage){
        Connection connection = null;
        PreparedStatement ps = null;
        ResultSet resultSet = null;

        try{
            //获取连接
            connection = JdbcUtils.getConnection();
            //创建PreparedStatement对象
            ps = connection.prepareStatement("select * from users where username = ? and userage = ?");
            //绑定参数
            ps.setString(1,username);
            ps.setInt(2,userage);

            //执行sql
            resultSet = ps.executeQuery();
            //处理结果集
            while (resultSet.next()){
                int userid = resultSet.getInt("userid");
                String name = resultSet.getString("username");
                int age = resultSet.getInt("userage");
                System.out.println(userid+" "+name+" "+age);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            JdbcUtils.CloseResource(resultSet,ps,connection);
        }
    }


    public static void main(String[] args){
        SqlInjectTest sit = new SqlInjectTest();
       // sit.sqlInTest("oldlu' or 1=1 --",28);
       sit.noSqlInject("oldlu' or 1=1 --",28);
    }
}


JAVA 全系列/第三阶段:数据库编程/JDBC技术 12013楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 12014楼
Python 全系列/第一阶段:Python入门/Python入门(动画版) 12015楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637