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

📄 newgoodsbean.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 newgoodsBean 
{
  Connection con=null;
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  PreparedStatement pstmt1=null;
  ResultSet rs1=null;
  public boolean addnewgoods(newgoods ng) throws Exception
  {
    boolean res=false;
    try 
    {
      con=DBConnect.getConnection();
      pstmt=con.prepareStatement("insert into newgoods values(?,?)");
      pstmt.setString(1,ng.getngid());
      pstmt.setString(2,ng.getGoodsid());
      pstmt.executeUpdate();
      pstmt.close();
      con.close();
      res=true;
    } 
    catch (Exception ex) 
    {
      ex.printStackTrace();
    } 
    
    return res;
  }

  public boolean updatenewgoods(newgoods ng) throws Exception
  {
    
    boolean res=false;
    try 
    {
      con=DBConnect.getConnection();
      pstmt=con.prepareStatement("update newgoods set goodsid=? where ngid=?");
      pstmt.setString(1,ng.getGoodsid());
      pstmt.setString(2,ng.getngid());
      pstmt.executeUpdate();
      pstmt.close();
      con.close();
      res=true;
    } 
    catch (Exception ex) 
    {
      ex.printStackTrace();
    } 
    
    return res;
  }

  public boolean delnewgoods(String id)
  {
    boolean res=false;
    try 
    {
      con=DBConnect.getConnection();
      pstmt=con.prepareStatement("delete from newgoods where ngid=?");
      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 newgoods where ngid=?");
      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 findnewgoods(newgoods ng) throws Exception
  {
    Vector v=new Vector();
    try 
    {
      con=DBConnect.getConnection();
      if(ng.getngid().equals("")&&ng.getGoodsid().equals(""))
      {
        pstmt1=con.prepareStatement("select * from newgoods");
        rs1=pstmt1.executeQuery();
        while(rs1.next())
        {
          newgoods te=new newgoods();
          te.setngid(rs1.getString(1));
          te.setGoodsid(rs1.getString(2));
          v.add(te);
        }
      }
      else
      {
        String s=" where ";
        if(!ng.getngid().equals(""))
          s=s+"ngid like '%"+ng.getngid()+"%' and";
        if(!ng.getGoodsid().equals(""))
          s=s+" goodsid like '%"+ng.getGoodsid()+"%' and";
        if(s.equals(" where "))
          s="";
        else
          s=s.substring(0,s.lastIndexOf(" "));
          pstmt=con.prepareStatement("select * from newgoods"+s+"");
          rs=pstmt.executeQuery();
          while(rs.next())
          {
              newgoods te=new newgoods();
              te.setngid(rs.getString(1));
              te.setGoodsid(rs.getString(2));
              v.add(te);
          }
      }
    } 
    catch (Exception ex) 
    {
      ex.printStackTrace();
    } 
    
    return v;
  }
}

⌨️ 快捷键说明

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