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

📄 sessions.java

📁 有完整的毕业设计所需的文件和代码 没什么说的了
💻 JAVA
字号:
package db;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import vo.*;
public class Sessions {

	Connection con;
	public Sessions(){
		
		con=SessionFactory.get_con();
	}
	
	
	//特价商品
	public List get_t_value(){
		String sql="select * from pro where isvalue='"+"1"+"'";
		
		return this.query(sql);
	}
	
	//精品推荐
	public List get_j(){
		String sql="select * from pro where state='"+"1"+"'";
		return this.query(sql);
	}
	
	//新品上市
	public List get_x(){
		String sql="select * from pro where state='"+"0"+"' order by p_date desc";
		return this.query(sql);
	}
	//畅销排行榜
	public List get_c(){
		String sql="select top 10 * from pro order by num desc";
		return this.query(sql);
		
	}
	//手机
	public List get_phone(){
		
		String sql="select  * from pro where kind='"+"手机"+"'";
		return this.query(sql);
	}
	//相机
	public List get_camera(){
		
		String sql="select  * from pro where kind='"+"相机"+"'";
		return this.query(sql);
	}
	//mp3
	public List get_mp3(){
		
		String sql="select  * from pro where kind='"+"mp3"+"'";
		return this.query(sql);
	}
	//电脑
	public List get_computer(){
		
		String sql="select  * from pro where kind='"+"电脑"+"'";
		return this.query(sql);
	}
	//电视
	public List get_tv(){
		
		String sql="select  * from pro where kind='"+"电视"+"'";
		return this.query(sql);
	}
	
	
	//更新用户
	public void updateUser(User u){
		String sql="update re_user set name='"+u.getName()+"',realname='"+u.getRealname()+"',sex='"+u.getSex()+"',ph='"+u.getPh()+"',cardId='"+u.getCardId()+"' where id="+u.getId();
		try {Statement st=con.createStatement();
		   int n=st.executeUpdate(sql);
	
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
	
		}
	}
	
	//
	public boolean change(int id,String old ,String newp){
		String sql="select * from re_user where id="+id+" and pwd='"+old+"'";
		String sql2="update re_user set pwd='"+newp+"'";
		try{
			Statement st=con.createStatement();
			ResultSet re=st.executeQuery(sql);
			if (re.next()){
				st.executeUpdate(sql2);
				return true;
				
			}
			else return false;
			
			
		}catch(Exception e){
			
			e.printStackTrace();
			return false;
		}
		
		
	}
	public Pro get_pro_by_id(String id){
		Pro p=new Pro();
		int d=Integer.parseInt(id.trim());
		String sql="select * from pro where id="+d;
		try{
		Statement st=con.createStatement();
		ResultSet re=st.executeQuery(sql);
		if(re.next())
		p=Convert.c_pro(re);
		
		}catch(Exception e){
			e.printStackTrace();
		}
		return p;
	}
	
	
	//注册用户
	public boolean reg(User u){
		String sql="insert into re_user(name,pwd,sex,ph,cardId,realname) values('"+u.getName()+"','"+u.getPwd()+"','"+u.getSex()+"','"+u.getPh()+"','"+u.getCardId()+"','"+u.getRealname()+"')";
		try {Statement st=con.createStatement();
		   int n=st.executeUpdate(sql);
		   if(n>0)return true;
		   else return false;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}
	//登陆
	public User checkUser(String name,String pwd){
		String  sql="";
		sql="select * from re_user where name='"+name+"' and pwd='"+pwd+"'";
		
		try {
			Statement st=con.createStatement();
			ResultSet re=st.executeQuery(sql);
			if(re.next())
		    return Convert.c_u(re);
			else return null;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}
	
	//所有产品
	public List findAll(){
		
		String sql="select * from pro";
		try{
			return this.query(sql);
			
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	//删除
	public void delbyid(String id){
		int n=Integer.parseInt(id.trim());
		String sql="delete from pro where id="+n;
		try{
			Statement st=con.createStatement();
			st.executeUpdate(sql);
			
		}catch(Exception e){
			
			e.printStackTrace();
		}
	}
	
	//
	public Pro findByBianhao(String b){
		String sql="select * from pro where bianhao='"+b+"'";
		try{
			Pro p=null;
			Statement st=con.createStatement();
			ResultSet re=st.executeQuery(sql);
			if(re.next()){
				p=Convert.c_pro(re);
			}
			return p;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	public Admin checkAdmin(String name,String pwd){
		String  sql="";
		sql="select * from admin where name='"+name+"' and pwd='"+pwd+"'";
		
		try {
			Statement st=con.createStatement();
			ResultSet re=st.executeQuery(sql);
			if(re.next())
		    return Convert.c_admin(re);
			else return null;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}
	
	//插入订单
	public void add_d(D d){
		String sql="insert into d_table(pro_id,buy_date,user_id) values('"+d.getPro_id()+"','"+d.getBuy_date()+"','"+d.getUser_id()+"')";
		try {Statement st=con.createStatement();
		   int n=st.executeUpdate(sql);
		
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
	
		}
	}
	
	//
	public List find_d(int id){
		
		String sql="select * from d_table where user_id="+id;
		return this.query_d(sql);
		
	
	}
	public List query(String sql){
		ArrayList list=new ArrayList();
		try {
			Statement st=con.createStatement();
			ResultSet re=st.executeQuery(sql);
			while(re.next()){
			 Pro p=Convert.c_pro(re);	
			 list.add(p);
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return list;
	}
	
	public List query_d(String sql){
		ArrayList list=new ArrayList();
		try {
			Statement st=con.createStatement();
			ResultSet re=st.executeQuery(sql);
			while(re.next()){
			 D p=Convert.c_d(re);	
			 list.add(p);
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return list;
	}
	
}

⌨️ 快捷键说明

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