其他分享
首页 > 其他分享> > 增删改查(新)

增删改查(新)

作者:互联网

private QueryRunner queryRunner= new QueryRunner(DButil.getDruidDataSource()) ;

    public boolean insert(person person)
    {
        Object[] parms = {person.getName(),person.getAge(),person.getSchool()};
        boolean result1 = false;
        try {
            int result = queryRunner.update("insert into person(name,age,school) value (?,?,?)",parms);
            if(result==1)
                result1 = true;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return result1;
    }

    public boolean update(person person)
    {
        Object[] parms = {person.getAge(),person.getSchool(),person.getName()};
        boolean result = false;
        try {
            int result1 = queryRunner.update("update person set age = ?,school = ? where name = ?",parms);
            if (result1 == 1)
                result = true;
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return result;
    }

    public boolean delete(String name)
    {
        boolean result = false;
        Object[] parms = {name};
        try {
            int result1 = queryRunner.update("delete from person where name = ?");
            if (result1==1)
                result = true;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return result;
    }

    public person select(String name)
    {
        person person = null;
        try {
            person = queryRunner.query("select * from person where name = ?",new BeanHandler<person>(com.bean.person.class),name);
            return person;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public List<person> selectAll()
    {
        try {
            List<person> personList = queryRunner.query("select * from person",new BeanListHandler<person>(person.class));
            return personList;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

 

标签:return,name,改查,result1,person,boolean,result,增删
来源: https://www.cnblogs.com/-0112/p/15511558.html