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

📄 userdao.java

📁 用ssh实现的简单通讯录+需要数据库
💻 JAVA
字号:
package Dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import po.HibernateSessionFactory;

public class userDao {
	public Object getobject(Class c,Integer i){
		Session session=HibernateSessionFactory.getSession();
		Object obj=session.get(c, i);
		session.close();
		return obj;
	}
public List getserch(po.Userinfo user){

	Session session=HibernateSessionFactory.getSession();
	String hql="select u.userid from Userinfo as u where u.uname=? and u.upass=? ";
	Query query=session.createQuery(hql);
	query.setString(0, user.getUname());
	query.setString(1, user.getUpass());
	List list=query.list();
	session.close();
	return list;
}

public boolean  updateuser(po.Userinfo user){
	boolean n=false;
	Session session=HibernateSessionFactory.getSession();
   Transaction tran=session.beginTransaction();
	try{
		session.saveOrUpdate(user);
		tran.commit();
		n=true;
	}catch(Exception ex){
		ex.printStackTrace();
		tran.rollback();
		n=false;
	}finally{	
		session.close();
	}
	return n;
}
public boolean  updateinfo(po.Conectinfo cnf){
	boolean n=false;
	Session session=HibernateSessionFactory.getSession();
   Transaction tran=session.beginTransaction();
	try{
		session.saveOrUpdate(cnf);
		tran.commit();
		n=true;
	}catch(Exception ex){
		ex.printStackTrace();
		tran.rollback();
		n=false;
	}finally{	
		session.close();
	}
	return n;
}

public boolean deleteconf(po.Conectinfo cnf){
	boolean n=false;
		Session session=HibernateSessionFactory.getSession();
		Transaction tran=session.beginTransaction();		
		try{
		session.delete(cnf);
		tran.commit();
		n=true;
		}catch(Exception ex){
			ex.printStackTrace();
			tran.rollback();
			n=false;
		}finally{	
		session.close();	
		}
		return n;
	}
public List getserch2(Integer id){

	Session session=HibernateSessionFactory.getSession();
	String hql="select c.lxid,c.name,t.utname,c.sexid,c.phone,c.mphone,c.cpyname,c.cpyaddress,c.address from po.Conectinfo as c,po.Userinfo as u,po.Conecttype as t where c.userinfo=u and c.conecttype=t and u.userid="+id+"  ";
	Query query=session.createQuery(hql);
	List list=query.list();

	return list;
}
public List getserch3(Integer id,String name){

	Session session=HibernateSessionFactory.getSession();
	String hql="select c.lxid,c.name,t.utname,c.sexid,c.phone,c.mphone,c.cpyname,c.cpyaddress,c.address from po.Conectinfo as c,po.Userinfo as u,po.Conecttype as t where c.userinfo=u and c.conecttype=t and u.userid="+id+" and c.name like'%"+name+"%' ";
	Query query=session.createQuery(hql);
	List list=query.list();
	return list;
}
public List pageone(int pageNo,int pageSize,Integer id){
	Session session=HibernateSessionFactory.getSession();
	String sql="select c.lxid,c.name,t.utname,c.sexid,c.phone,c.mphone,c.cpyname,c.cpyaddress,c.address from po.Conectinfo as c,po.Userinfo as u,po.Conecttype as t where c.userinfo=u and c.conecttype=t and u.userid="+id+" ";
	Query query=session.createQuery(sql);
	int beginnumber=pageSize*(pageNo-1);
	query.setFirstResult(beginnumber);
	query.setMaxResults(pageSize);
	List list=query.list();
	return list;
}
}

⌨️ 快捷键说明

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