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

📄 goodsinfobean.java

📁 精美的画面。完善的功能
💻 JAVA
字号:
package Flower.model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
import java.util.Collection;
public class GoodsInfoBean 
{
  Connection con=null;
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  PreparedStatement pstmt1=null;
  ResultSet rs1=null;
  public boolean addGoodsInfo(Goodsinfo gif) throws Exception
  {
    boolean res=false;
    try 
    {
      con=DBConnect.getConnection();
      pstmt=con.prepareStatement("insert into GoodsInfo values(?,?,?,?,?,?)");
      pstmt.setString(1,gif.getGoodsid());
      pstmt.setString(2,gif.getFlowerid());
      pstmt.setDouble(3,gif.getRetailprice());
      pstmt.setDouble(4,gif.getCostprice());
      pstmt.setString(5,gif.getSupid());
      pstmt.setString(6,gif.getAttr());
      pstmt.executeUpdate();
      pstmt.close();
      con.close();
      res=true;
    } 
    catch (Exception ex) 
    {
      ex.printStackTrace();
    } 
    
    return res;
  }

  public boolean updateGoodsInfo(Goodsinfo gif) throws Exception
  {
    
    boolean res=false;
    try 
    {
      con=DBConnect.getConnection();
      pstmt=con.prepareStatement("update Goodsinfo set Flowerid=?,RetailPrice=?,Costprice=?,Supid=?,Attr=? where GoodsID=?");
      
      pstmt.setString(1,gif.getFlowerid());
      pstmt.setDouble(2,gif.getRetailprice());
      pstmt.setDouble(3,gif.getCostprice());
      pstmt.setString(4,gif.getSupid());
      pstmt.setString(5,gif.getAttr());
      pstmt.setString(6,gif.getGoodsid());
      pstmt.executeUpdate();
      pstmt.close();
      con.close();
      res=true;
    } 
    catch (Exception ex) 
    {
      ex.printStackTrace();
    } 
    
    return res;
  }

  public boolean delGoodsInfo(String id)
  {
    boolean res=false;
    try 
    {
      con=DBConnect.getConnection();
      pstmt=con.prepareStatement("delete from GoodsInfo where GoodsID=?");
      pstmt.setString(1,id);
      pstmt.executeUpdate();
      pstmt.close();
      con.close();
      res=true;
    } 
    catch (Exception ex) 
    {
      ex.printStackTrace();
    } 
    
    return res;
  }

  public boolean getID(String id)
  {
    boolean res=false;
    try 
    {
      con=DBConnect.getConnection();
      pstmt=con.prepareStatement("select *  from GoodsInfo where GoodsID=?");
      pstmt.setString(1,id);
      rs=pstmt.executeQuery();
      if(rs.next())
      {
        res=true;
      }
      else
      {
        res=false;
      }
      rs.close();
      pstmt.close();
      con.close();
      
    } 
    catch (Exception ex) 
    {
      ex.printStackTrace();
    } 
    
    return res;
  }

  public Collection findGoodsInfo(Goodsinfo gif) throws Exception
  {
    Vector v=new Vector();
    try 
    {
      con=DBConnect.getConnection();
      if(gif.getGoodsid().equals("")&&gif.getFlowerid().equals("")&&gif.getSupid().equals(""))
      {
        pstmt1=con.prepareStatement("select * from goodsinfo");
        rs1=pstmt1.executeQuery();
        while(rs1.next())
        {
          Goodsinfo gi=new Goodsinfo();
          gi.setGoodsid(rs1.getString(1));
          gi.setFlowerid(rs1.getString(2));
          gi.setRetailprice(rs1.getDouble(3));
          gi.setCostprice(rs1.getDouble(4));
          gi.setSupid(rs1.getString(5));
          gi.setAttr(rs1.getString(6));
          v.add(gi);
        }
      }
      else
      {
        String s=" where ";
        if(!gif.getGoodsid().equals(""))
          s=s+"goodsid like '%"+gif.getGoodsid()+"%' and";
        if(!gif.getFlowerid().equals(""))
          s=s+" flowerid like '%"+gif.getFlowerid()+"%' and";
        if(!gif.getSupid().equals(""))
          s=s+" supid like '%"+gif.getSupid()+"%' and";
        if(s.equals(" where "))
          s="";
        else
          s=s.substring(0,s.lastIndexOf(" "));
          pstmt=con.prepareStatement("select * from goodsinfo"+s+"");
          rs=pstmt.executeQuery();
          while(rs.next())
          {
            Goodsinfo gi=new Goodsinfo();
            gi.setGoodsid(rs.getString(1));
            gi.setFlowerid(rs.getString(2));
            gi.setRetailprice(rs.getDouble(3));
            gi.setCostprice(rs.getDouble(4));
            gi.setSupid(rs.getString(5));
            gi.setAttr(rs.getString(6));
            v.add(gi);
          }
      }
    } 
    catch (Exception ex) 
    {
      ex.printStackTrace();
    } 
    
    return v;
  }
}

⌨️ 快捷键说明

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