⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 people.java

📁 这是一本关于高级软件工程的书籍
💻 JAVA
字号:
package org.tsinghua.netshop.beans;

import java.util.*;
import org.tsinghua.netshop.beans.*;
import java.sql.*;

public class People {

    private String username;
    private int uid;
    private String uname;
    private String password;
    private int postalcode;
    private String phone;
    private String address;
    private String email;
    public static DBConnection cn = new DBConnection("localhost", "netshop");


    public void setEmail(String email) {
        this.email = email;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public void setPostalcode(int postalcode) {
        this.postalcode = postalcode;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setUid(int uid) {
        this.uid = uid;
    }

    public void setUname(String uname) {
        this.uname = uname;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAddress() {
        return address;
    }

    public String getUsername() {
        return username;
    }

    public int getUid() {
        return uid;
    }

    public String getUname() {
        return uname;
    }

    public String getPassword() {
        return password;
    }

    public String getEmail() {
        return email;
    }

    public String getPhone() {
        return this.phone;
    }

    public int getPostalcode() {
        return postalcode;
    }


    public boolean insert() {
        String sql="insert into people values('" + username + "','" +
                         password + "','" + uname + "','" + phone + "','" + email +
                         "'," + postalcode + ",'" + address + "')";
        boolean b=cn.update(sql);

        return b;
    }

    public static ArrayList findAll() throws Exception {
        ResultSet rs = cn.select("select * from people");
        ArrayList a = new ArrayList();
        while (rs.next()) {
            People p = new People();
            p.uid = rs.getInt(1);
            p.setUsername(rs.getString(2));
            p.setPassword(rs.getString(3));
            p.setUname(rs.getString(4));
            p.setPhone(rs.getString(5));
            p.setEmail(rs.getString(6));
            p.setPostalcode(rs.getInt(7));
            p.setAddress(rs.getString(8));
            a.add(p);
        }
        return a;
    }

    public boolean validate(String username, String password) throws Exception {
        ResultSet rs = cn.select("select uname from people where username='" +
                                 username + "' and password='" + password + "'");
        if (rs.next()) {
            this.uname = rs.getString(1);
            return true;
        } else {
            return false;
        }
    }

    public boolean update() {
        return cn.update("update people set username='" + username +
                         "',password='" + password + "',uname='" + uname +
                         "',phone='" + phone + "',email='" + email +
                         "',postalcode=" + postalcode + ",address='" + address +
                         "' where username=" + this.getUsername());
    }

    public boolean loadByUsername(String username) {
        ResultSet rs = cn.select("select * from people where username='" +
                                 username + "'");
        try {
            if (rs.next()) {
                this.uid = rs.getInt(1);
                this.username = rs.getString(2);
                this.password = rs.getString(3);
                this.uname = rs.getString(4);
                this.phone = rs.getString(5);
                this.email = rs.getString(6);
                this.postalcode = rs.getInt(7);
                this.address = rs.getString(8);
                return true;
            } else {

                return false;
            }
        } catch (SQLException ex) {
            return false;
        } catch (Exception ex) {
            return false;
        }

    }

    /*	public static void  main(String args[])throws Exception {
                    System.out.println(People.validate("aaa","1111f"));
                    Collection c=People.findAll();
                    Iterator it=c.iterator();
                    while(it.hasNext()){
                            People p=(People)it.next();
                            p.setPassword("111");
                            p.update();
                            System.out.println(p.getUsername());
                    }
                    People p=new People();
                    p.loadByUid(3);
            }
     */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -