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

📄 petowner.java~21~

📁 一个基于JAVA的BS结构的宠物诊所管理系统.是当年在学校时写的,大家指点一下.
💻 JAVA~21~
字号:
package gxaccp.t07.guoneng_wei.petclinicmanagesystem.actionform;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.sql.*;
import gxaccp.t07.guoneng_wei.jdbc.DataBaseAccess;

public class PetOwner
    extends ActionForm { //id ownerName sex telephone address
  private String id; //--编号
  private String ownerName; //--所有者姓名
  private String sex; //--性别
  private String telephone; //-- 电话
  private String address; //--地址/

  private Vector petOwners;
  public ActionErrors validate(ActionMapping actionMapping,
                               HttpServletRequest httpServletRequest) {
    /** @todo: finish this method, this is just the skeleton.*/
    return null;
  }

  public void reset(ActionMapping actionMapping,
                    HttpServletRequest servletRequest) {
    id = ""; //--编号
    ownerName = ""; //--所有者姓名
    sex = ""; //--性别
    telephone = ""; //-- 电话
    address = ""; //--地址/
    petOwners=null;
  }

  public String getAddress() {
    return address;
  }

  public String getOwnerName() {
    return ownerName;
  }

  public String getSex() {
    return sex;
  }

  public String getTelephone() {
    return telephone;
  }

  public String getId() {
    return id;
  }

  public Vector getPetOwners() {
    return petOwners;
  }

  public void setTelephone(String telephone) {
    this.telephone = telephone;
  }

  public void setSex(String sex) {
    this.sex = sex;
  }

  public void setOwnerName(String ownerName) {
    this.ownerName = ownerName;
  }

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

  public void setId(String id) {
    this.id = id;
  }

  public void setPetOwners(Vector petOwners) {
    this.petOwners = petOwners;
  }

  public boolean addPetOwnerInfo() {
    Connection con = DataBaseAccess.getConnection();
    CallableStatement cst = null;
    try {
      // EXEC proc_insertPetOwnerInfo @OutID OUTPUT, '李媚娘',1,'13878705250','南宁市凤凰小区'
      cst = con.prepareCall("{call proc_insertPetOwnerInfo(?,?,?,?,?)}");
      cst.registerOutParameter(1, java.sql.Types.VARCHAR);
      cst.setString(2, this.getOwnerName());
      cst.setInt(3, Integer.parseInt(this.getSex()));
      cst.setString(4, this.getTelephone());
      cst.setString(5, this.getAddress());
      cst.execute();
      String poid = cst.getString(1);
      if (poid != null) {
        this.setId(poid);
        return true;
      }
    }
    catch (SQLException ex) {
      System.out.println("-------------出现异常在添加宠物所有者的信息时---------------");
    }
    finally {
      DataBaseAccess.closeStatement(cst);
      DataBaseAccess.closeConnection(con);
    }
    return false;
  }

  public boolean searchPetOwner() {
    Connection con = DataBaseAccess.getConnection();
       PreparedStatement pst = null;
       ResultSet rs = null;
       boolean flag=false;
//    ID       OwnerName  Sex  Telephone    Address
       try {
         pst = con.prepareStatement("SELECT * FROM PetOwnerInfo WHERE OwnerName=?");
         rs = pst.executeQuery();
         this.petOwners=new Vector();
         while (rs.next()) {
           flag=true;
           PetOwner po=new PetOwner();
           po.setId(rs.getString("ID"));
           po.setOwnerName(rs.getString("OwnerName"));
           po.setSex(rs.getString("Sex"));
           po.setTelephone(rs.getString("Telephone"));
           po.setAddress(rs.getString("Address"));
           this.petOwners.addElement(po);
         }
         if(flag)return true;
       }
       catch (SQLException ex) {
         System.out.println(
             "-------------出现异常在searchPetOwner( )中---------------");
       }
       finally {
         DataBaseAccess.closeResultSet(rs);
         DataBaseAccess.closeStatement(pst);
         DataBaseAccess.closeConnection(con);
       }
       return false;
   }

  public boolean selectPetOwnerInfo(String sql) {
      Connection con = DataBaseAccess.getConnection();
      PreparedStatement pst = null;
      ResultSet rs = null;
      boolean flag=false;
//    ID       OwnerName  Sex  Telephone    Address
      try {
        pst = con.prepareStatement(sql);
        rs = pst.executeQuery();
        this.petOwners=new Vector();

        while (rs.next()) {
          flag=true;
          PetOwner po=new PetOwner();
          po.setId(rs.getString("ID"));
          po.setOwnerName(rs.getString("OwnerName"));
          po.setSex(rs.getString("Sex"));
          po.setTelephone(rs.getString("Telephone"));
          po.setAddress(rs.getString("Address"));
          this.petOwners.addElement(po);
        }
        if(flag)return true;
      }
      catch (SQLException ex) {
        System.out.println(
            "-------------出现异常在selectPetOwnerInfo(String sql)中---------------");
      }
      finally {
        DataBaseAccess.closeResultSet(rs);
        DataBaseAccess.closeStatement(pst);
        DataBaseAccess.closeConnection(con);
      }
      return false;
  }

  public boolean updatePetOwnerInfo() {
    Connection con = DataBaseAccess.getConnection();
    PreparedStatement pst = null;
//     ID       OwnerName  Sex  Telephone    Address
    try {
      pst = con.prepareStatement(
          "UPDATE PetOwnerInfo SET OwnerName=?,Sex=?,Telephone=?,Address=? WHERE ID=?");
      pst.setString(1, this.getOwnerName());
      pst.setInt(2, Integer.parseInt(this.getSex()));
      pst.setString(3, this.getTelephone());
      pst.setString(4, this.getAddress());
      pst.setString(5, this.getId());
      if (pst.executeUpdate()>0) {
        return true;
      }
    }
    catch (SQLException ex) {
      System.out.println(
          "-------------出现异常在updatePetOwnerInfo()中---------------");
    }
    finally {
      DataBaseAccess.closeStatement(pst);
      DataBaseAccess.closeConnection(con);
    }
    return false;
  }
}

⌨️ 快捷键说明

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