package com.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.bean.Shop;
import com.util.JDBCUtil;
public class Dao {
		
	public static int getcount(){
		int count=0;
		Connection conn = JDBCUtil.getconn();
		try {
			PreparedStatement ps = conn.prepareStatement("select count(*) from shop");
			ResultSet rs = ps.executeQuery();
			if (rs.next()) {
				count=rs.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}
	public static ArrayList<Shop> query(String id,String name,String content,String start,String end,String bname){
		ArrayList<Shop> list = new ArrayList<Shop>();
		Connection conn = JDBCUtil.getconn();
		String sql="select  s.*,b.bname from shop s,brand b where s.bid = b.bid  ";
		if (id!=null&&!"".equals(id)) {
			sql+="and id='"+id+"'";
		}
		if (name!=null&&!"".equals(name)) {
			sql+="and name like '%"+name+"%'";
		}
		if (content!=null&&!"".equals(content)) {
			sql+="and content like '%"+content+"%'";
		}
		if (start!=null&&!"".equals(start)&&end!=null&&!"".equals(end)) {
			sql+="and datea >= to_date('"+start+"','yyyy-MM-dd HH24:mi:ss') and datea <= to_date('"+end+"','yyyy-MM-dd HH24:mi:ss')";
		}
		if (bname!=null&&!"".equals(bname)) {
			sql+="and b.bname like '%"+bname+"%'";
		}
		String sql1="select * from ("+sql+")";
		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while(rs.next()){
				Shop s = new Shop(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getInt(5), rs.getString(6));
				list.add(s);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	public static int del(String id){
		int i=0;
		Connection conn = JDBCUtil.getconn();
		try {
			PreparedStatement ps = conn.prepareStatement("delete shop where id in ("+id+")");
			i = ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}
	
	public static ArrayList<Shop> show(int currpage, int pagesize){
		ArrayList<Shop> list = new ArrayList<Shop>();
		Connection conn = JDBCUtil.getconn();
		String sql="";
		
		try {
			PreparedStatement ps = conn.prepareStatement("select * from (select  s.*,b.bname,rownum r from shop s,brand b where s.bid = b.bid) where r>? and r<?");
			ps.setInt(1,pagesize*(currpage-1));
			ps.setInt(2,pagesize*currpage+1);
			ResultSet rs = ps.executeQuery();
			while(rs.next()){
				Shop s = new Shop(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getInt(5), rs.getString(6));
				list.add(s);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	public static int adds(String name,String content,String datea,String bid){
		int i=0;
		Connection conn = JDBCUtil.getconn();
		try {
			PreparedStatement ps = conn.prepareStatement("insert into shop values(stu_squ.nextval,?,?,to_date(?,'yyyy-MM-dd HH24:mi:ss'),?)");
			ps.setString(1, name);
			ps.setString(2, content);
			ps.setString(3, datea);
			ps.setString(4, bid);
			i = ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}
	public static int xg(String name,String content,String datea,String bid,String id){
		int i=0;
		Connection conn = JDBCUtil.getconn();
		try {
			PreparedStatement ps = conn.prepareStatement("update shop set name=?,content=?,datea=to_date(?,'yyyy-MM-dd HH24:mi:ss'),bid=? where id=?");
			ps.setString(1, name);
			ps.setString(2, content);
			ps.setString(3, datea);
			ps.setString(4, bid);
			ps.setString(5, id);
			i = ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}
	public static ArrayList<Shop> toAdd(){
		ArrayList<Shop> list = new ArrayList<Shop>();
		Connection conn = JDBCUtil.getconn();
		String sql="select * from brand";
		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while(rs.next()){
				Shop s = new Shop(rs.getInt(1), rs.getString(2));
				list.add(s);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	public static Shop upd(String id){
		Shop s=null;
		Connection conn = JDBCUtil.getconn();
		String sql="select * from shop where id=?";
		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setString(1, id);
			ResultSet rs = ps.executeQuery();
			while(rs.next()){
				s = new Shop(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getInt(5),null);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return s;
	}
}
 最近下载更多
最近下载更多
                
                ma406805131     LV19
                2024年6月18日
            
            
        
                asddwh     LV13
                2024年1月1日
            
            
        
                微信网友_6776859393560576     LV1
                2023年12月13日
            
            
        
                ericxu1116     LV24
                2023年6月14日
            
            
        
                95959595959     LV13
                2023年4月20日
            
            
        
                lzl111213     LV1
                2023年4月19日
            
            
        
                331376387     LV5
                2023年1月9日
            
            
        
                微信网友_5992582549164032     LV6
                2022年12月28日
            
            
        
                liangge2115     LV27
                2022年12月24日
            
            
        
                Tg171017     LV12
                2022年12月21日
            
            
         最近浏览更多
最近浏览更多
                
                renjunyou     LV10
                6月2日
            
            
        
                liyan54188     LV2
                2024年6月25日
            
            
        
                19hhhh    
                2024年6月23日
            
            
                    暂无贡献等级
            
        
                ma406805131     LV19
                2024年6月18日
            
            
        
                一起加油     LV5
                2024年5月14日
            
            
        
                李朝磊     LV18
                2024年5月9日
            
            
        
                微信网友_6815604991741952     LV1
                2024年1月10日
            
            
        
                Liang朝伟     LV1
                2024年1月5日
            
            
        
                沈从文     LV3
                2024年1月1日
            
            
        
                颜菜菜     LV2
                2023年12月30日
            
            
        
 
                 
                 
                