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

📄 goodtypedao.java

📁 网上购物系统
💻 JAVA
字号:
package eshopsys.goodtype.model;

import java.sql.*;
import java.util.*;
import eshopsys.tools.base.BaseDao;
import eshopsys.tools.base.BaseEntity;
import eshopsys.tools.database.DataBaseTool;
import eshopsys.goodtype.model.*;

public class GoodTypeDao extends BaseDao {
//////////////////////////////////////////////////////////////////////////
	protected BaseEntity[] pack(ResultSet resultset) throws SQLException {
		 ArrayList result = new ArrayList();
		 GoodTypeEntity[] goods = null;
		    while (resultset.next()) {
		      GoodTypeEntity goodtype = new GoodTypeEntity();
		      goodtype.setGoodTypeId(resultset.getInt("goodtypeid"));
		      goodtype.setGoodType(resultset.getString("goodtype"));
		      result.add(goodtype);
		    }
		    if (result.size() > 0) {
		      goods= new GoodTypeEntity[result.size()];
		      result.toArray(goods);
		    }
		    return goods;

	}
//////////////////////////////////////////////////////////////////////////	
	public void insert(GoodTypeEntity goodtype) throws
    SQLException {
    PreparedStatement ps = null;
    StringBuffer buffer = new StringBuffer();
    try {
    //构造添加sql语句
    buffer.append("INSERT INTO tbl_goodtype(goodtypeid,goodtype)");
    buffer.append(" VALUES(?,?)");

    ps = con.prepareStatement(buffer.toString());
    //设置sql语句的参数
    int index = 1;
    int currentId=getMaxPrimaryId("tbl_goodtype","goodtypeid");
    ps.setInt(index++,currentId);
    ps.setString(index++, goodtype.getGoodType());
    
    //执行sql语句
    ps.executeUpdate();
  }
  catch (Exception e) {
    throw new SQLException("向表(tbl_goodtype)中插入数据发生异常 : " + e.getMessage());
  }
  finally {
    DataBaseTool.close(ps);
  }
 }
//////////////////////////////////////////////////////////////////////////
	//更新一条会员记录
	  public void update( GoodTypeEntity goodtype) throws     
	 SQLException {
	    PreparedStatement ps = null;
	    StringBuffer buffer = new StringBuffer();
	    try {
	      //构造更新sql语句
	      buffer.append("UPDATE tbl_goodtype SET ");
	      buffer.append("goodtypeid=?,goodtype=?");
	      buffer.append(" WHERE goodtypeid = ?");
	      ps = con.prepareStatement(buffer.toString());

	      //设置参数
	      int index = 1;
	      ps.setInt(index++, goodtype.getGoodTypeId());
	      ps.setString(index++, goodtype.getGoodType());
	      ps.setInt(index++, goodtype.getGoodTypeId());
	      //执行
	      ps.executeUpdate();
	    }
	    catch (Exception e) {
	      throw new SQLException("更新表(tbl_goodtype)时发生异常 : " + e.getMessage());
	    }
	    finally {
	      DataBaseTool.close(ps);
	    }
	  }

}

⌨️ 快捷键说明

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