petinfobean.java

来自「网上购物系统」· Java 代码 · 共 111 行

JAVA
111
字号
package Model_PetInfo;

import DataBase.ConDataBase;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Collection;

public class PetInfoBean 
{
  public PetInfoBean()
  {
  }

  public String InsertPetInfo(PetInfo pi)
  {
    Connection con=ConDataBase.getConnection();
    try{
    CallableStatement cmst=con.prepareCall("{call INSERTPETINFO(?,?,?,?,?,?)}");
    cmst.setString(1,pi.getPetID());
    cmst.setString(2,pi.getPetName());
    cmst.setString(3,pi.getTypeID());
    cmst.setString(4,pi.getPetPhoto());
    cmst.setString(5,pi.getDescriptions());
    cmst.registerOutParameter(6,Types.VARCHAR);
    
    cmst.execute();
    String re=cmst.getString(6);
    return re;
    }
    catch(Exception e)
    {
      System.out.println(e.getMessage());
      return e.getMessage();
    }
  }

  public String UpdatePetInfo(PetInfo pi)
  {
    Connection con=ConDataBase.getConnection();
    try{
    CallableStatement cmst=con.prepareCall("{call UPDATEPETINFO(?,?,?,?,?,?)}");
    cmst.setString(1,pi.getPetID());
    cmst.setString(2,pi.getPetName());
    cmst.setString(3,pi.getTypeID());
    cmst.setString(4,pi.getPetPhoto());
    cmst.setString(5,pi.getDescriptions());
    cmst.registerOutParameter(6,Types.VARCHAR);
    
    cmst.execute();
    String re=cmst.getString(6);
    return re;
    }
    catch(Exception e)
    {
      System.out.println(e.getMessage());
      return e.getMessage();
    }
  }

  public String DeletePetInfo(String petid)
  {
    Connection con=ConDataBase.getConnection();
    try{
    CallableStatement cmst=con.prepareCall("{call DELETEPETINFO(?,?)}");
    cmst.setString(1,petid);
    cmst.registerOutParameter(2,Types.VARCHAR);
    
    cmst.execute();
    String re=cmst.getString(2);
    return re;
    }
    catch(Exception e)
    {
      System.out.println(e.getMessage());
      return e.getMessage();
    }
  }

  public Collection SelectPetInfo()
  {
    Connection con=ConDataBase.getConnection();
    
    ArrayList al=new ArrayList();
    try{
    Statement smt=con.createStatement();
    ResultSet rs=smt.executeQuery("select * from PetInfo");
    while (rs.next())
    {
      PetInfo pi=new PetInfo();
      pi.setPetID(rs.getString(1));
      pi.setPetName(rs.getString(2));
      pi.setTypeID(rs.getString(3));
      pi.setPetPhoto(rs.getString(4));
      pi.setDescriptions(rs.getString(5));
      al.add(pi);
    }
    smt.close();
    con.close();
    return al;
    }
    catch(Exception e)
    {
      System.out.println(e.getMessage());
      return null;
    }
  }
}

⌨️ 快捷键说明

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