首页>代码>小型java购物车,实现购物车的增删改查简单功能>/购物车java项目/ShoppingSystem/src/www/mary/access/PowerAccess.java
package www.mary.access;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import www.mary.Bean.ItemBean;

import www.mary.database.BaseDAO;
import www.mary.Bean.*;
//一些通用的数据展现方法
public class PowerAccess {

	public PowerAccess() {
		super();

	}

//------------------------------------------------------------------------------------
	//展现产品大类所有的大类名称,先给Categorybean赋值,然后存放倒List里面
	public static List getCategoryName(){
		List list=new ArrayList();
		String sql="select * from category";
		System.out.println("------"+sql);
		BaseDAO dao=new BaseDAO();
		ResultSet rs=dao.executeQuery(sql);
		
		try {
			while(rs.next()){
				CategoryBean catename=new CategoryBean(rs.getString(1),rs.getString(2),rs.getString(3));
				list.add(catename);
     		}
		}catch (SQLException e) {
		        e.printStackTrace();
	  	}finally{
	  		dao.Close();
	  	}
	  	return list;
		
		
	  	
	}
	

//------------------------------------------------------------------------------------
	//展现产品大类catid所对应的产品名称,传递一个catid值
	public static List getProductList(String catid){
		List list=new ArrayList();
		String sql="select * from product where catid="+catid;
		System.out.println("------"+sql);
		BaseDAO dao=new BaseDAO();
		ResultSet rs=dao.executeQuery(sql);
		
		try {
			while(rs.next()){
				ProductBean product=new ProductBean(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4));
				list.add(product);
     		}
		}catch (SQLException e) {
		        e.printStackTrace();
	  	}finally{
	  		dao.Close();
	  	}
	  	return list;
		
		
	  	
	}


//------------------------------------------------------------------------------------
		//展现productid对应的产品项目,传递一个productid值
    public static List getItemlist(String productid){
		List list=new ArrayList();
		String sql="select itemid,productid,listprice,attr1 from item where productid="+productid;
		System.out.println("------"+sql);
		BaseDAO dao=new BaseDAO();
		ResultSet rs=dao.executeQuery(sql);
		
		try {
			while(rs.next()){
				ItemBean item=new ItemBean(rs.getString(1),rs.getString(2),rs.getDouble(3),rs.getString(4));  
				list.add(item);
     		}
		}catch (SQLException e) {
		        e.printStackTrace();
	  	}finally{
	  		dao.Close();
	  	}
	  	return list;

		
	}
	

//------------------------------------------------------------------------------------
			//展现itemid对应的产品项目的价格,状态,库存,传递一个itemid值
		public static List getlineitemlist(String itemid){
		    List list=new ArrayList();
			String sql="select A.descn,B.listprice,B.status,C.qty from product A,item B,inventory C where A.productid=B.productid and B.itemid=C.itemid and B.itemid='"+itemid+"'";
			System.out.println("------"+sql);
			BaseDAO dao=new BaseDAO();
			ResultSet rs=dao.executeQuery(sql);
			

			try {
				while(rs.next()){
					ItemInventoryBean one=new ItemInventoryBean(rs.getString(1),rs.getInt(2),rs.getString(3),rs.getInt(4));
	     		    list.add(one);
				} 
			}catch (SQLException e) {
			        e.printStackTrace();
		  	}finally{
		  		dao.Close();
		  	}
		  	return list;

			
		}
		


//------------------------------------------------------------------------------------
			
		//展现购物车中对应的产品项目编号,产品编号,描述,是否有库存,数量,价格,传递一个itemad值
		public static List getcartlist(String itemid){
		    List list=new ArrayList();
			String sql="select B.itemid,A.productid,B.attr1,B.status,C.qty,B.listprice from product A,item B,inventory C where A.productid=B.productid and B.itemid=C.itemid and B.itemid='"+itemid+"'";
			System.out.println("------"+sql);
			BaseDAO dao=new BaseDAO();
			ResultSet rs=dao.executeQuery(sql);
			

			try {
				while(rs.next()){
					ProitemBean one=new ProitemBean(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getInt(5));
	     		    list.add(one);
				} 
			}catch (SQLException e) {
			        e.printStackTrace();
		  	}finally{
		  		dao.Close();
		  	}
		  	return list;

			
		}
		

		public static ProitemBean getcart(String itemid){
			ProitemBean one=null;
			String sql="select B.itemid,A.productid,B.attr1,B.status,B.listprice from product A,item B,inventory C where A.productid=B.productid and B.itemid=C.itemid and B.itemid='"+itemid+"'";
			System.out.println("------"+sql);
			BaseDAO dao=new BaseDAO();
			ResultSet rs=dao.executeQuery(sql);
			

			try {
				while(rs.next()){
			    one=new ProitemBean(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getInt(5));
	     		   
				} 
			}catch (SQLException e) {
			        e.printStackTrace();
		  	}finally{
		  		dao.Close();
		  	}
		  	return one;

			
		}
		

//------------------------------------------------------------------------------------
			

		
//------------------------------------------------------------------------------------
		   //这是通用的校验用户合法性的程序
			public static boolean validateUser(String uname,String pword)
			{
				boolean isCorrect=false;
				String sql="select * from signon where username='"+uname+"' and password='"+pword+"'";
				//建立数据库连接,进行查询
				BaseDAO dao=new BaseDAO();
				//得到结果集合
				ResultSet rs=dao.executeQuery(sql);
				//如果查到了结果集合就不为空
				try {
					if(rs.next()){
						
					//在这里标签赋值乘true
						isCorrect=true;
						
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				dao.Close();
				return isCorrect;
				
				
			}

			
			
			
//------------------------------------------------------------------------------------

		    public static ItemBean getOneItem(String itemid)
		    {
		    	ItemBean one=null;
		          String sql="select * from item where itemid='"+itemid+"'";
		          BaseDAO dao=new BaseDAO();
		          ResultSet rs=dao.executeQuery(sql);
		          try{
		   		   if(rs.next())
		   		   {
		   			 one=new ItemBean(rs.getString(1),rs.getString(2),rs.getInt(3),rs.getDouble(4),rs.getDouble(5),rs.getString(6),
		                      rs.getString(7),rs.getString(8),rs.getString(9),rs.getString(10),rs.getString(11));   
		   		   
		   		   }
		   	    }catch (SQLException e){
		   		  e.printStackTrace();
		   	    }
		   	    dao.Close();
		   	    return one;	
		    }
}



















最近下载更多
rebest  LV2 2024年12月27日
23120450  LV1 2024年6月18日
郭宇航裹裹  LV5 2024年6月8日
微信网友_7005760998215680  LV6 2024年5月23日
statics  LV1 2024年5月7日
xiaotang156  LV2 2023年11月25日
2036495585  LV9 2023年9月25日
天士大夫  LV2 2023年5月25日
1004233692  LV1 2023年4月20日
itlaolang  LV6 2023年3月10日
最近浏览更多
rebest  LV2 2024年12月27日
微信网友_7313058229293056 2024年12月26日
暂无贡献等级
fankech  LV1 2024年11月4日
zmj040202  LV1 2024年10月28日
yanghu1632  LV1 2024年8月9日
微信网友_7043154826989568  LV1 2024年6月18日
微信网友_6992940666048512  LV1 2024年6月18日
23120450  LV1 2024年6月18日
郭宇航裹裹  LV5 2024年6月7日
微信网友_7005760998215680  LV6 2024年5月23日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友