




已阅读5页,还剩16页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/* 添加*/public void save(Stu stu)try tran=this.GetSession().beginTransaction();this.GetSession().save(stu);mit(); catch (HibernateException e) throw e;/* 添加*/public void save(Stu stu)try tran=this.GetSession().beginTransaction();this.GetSession().save(stu);mit(); catch (HibernateException e) throw e;finallythis.CloseSession();/* 使用HQL全查询*/public List getallbyHQL()List arr=null;try String hql=from Stu;Query query=this.GetSession().createQuery(hql);arr=query.list(); catch (HibernateException e) throw e;finallythis.CloseSession();return arr;/* 根据主键查询*/public Stu getbyID(int id)Stu stu=null;try stu=(Stu) this.GetSession().get(Stu.class, id); catch (HibernateException e) throw e;finallythis.CloseSession();return stu;/* 根据对象属性查询(使用Query)*/public List getbyPropertyQuery(String name)List arr=null;try /这里不能像SQL语一样select * from Stu where SName=:name,这是不对的。/ Query query=this.GetSession().createQuery(from Stu where SName=:name);/ query.setString(name, name);/或者Query query=this.GetSession().createQuery(from Stu where SName=?);query.setString(0, name);arr=query.list(); catch (HibernateException e) throw e;finallythis.CloseSession();return arr;/* 根据对象属性查询(使用Criteria)*/public List getbyPropertyCriteria(String name)List arr=null;try Criteria cri=this.GetSession().createCriteria(Stu.class);Criterion c1=Expression.eq(SName, name);cri.add(c1);arr=cri.list(); catch (HibernateException e) throw e;finallythis.CloseSession();return arr;/* 查询部分属性*/public List getProperty()List arr=new ArrayList();try String hql=select s.SName,s.SSex from Stu as s;Query query=this.GetSession().createQuery(hql);List list=query.list();Iterator iter=list.iterator();while(iter.hasNext()Object obj=(Object) iter.next();Stu s=new Stu();s.setSName(obj0.toString();s.setSSex(obj1.toString();arr.add(s); catch (HibernateException e) this.CloseSession();return arr;/* 查询一个属性*/public List getoneProperty()List arr=new ArrayList();try String hql=select s.SName from Stu as s;Query query=this.GetSession().createQuery(hql);Iterator iter=query.iterate();while(iter.hasNext()Object obj=(Object) iter.next();Stu s=new Stu();s.setSName(obj.toString();arr.add(s); catch (HibernateException e) this.CloseSession();return arr;/*查询一个对象一个属性值*/public Object getonlyProprotyValue(int s_id)Object obj=null;try String hql=select s.SName from Stu as s where s.SId=?;Query query=this.GetSession().createQuery(hql);query.setInteger(0, s_id);obj=query.uniqueResult(); catch (HibernateException e) throw e;finallythis.CloseSession();return obj;/* SQL查询*/public List getallBYSQL()List arr=null;try String sql=select c.* from stu as c;SQLQuery sqlquery=this.GetSession().createSQLQuery(sql);sqlquery.addEntity(c,Stu.class);arr=sqlquery.list(); catch (HibernateException e) throw e;finallythis.CloseSession();return arr;/* 根据对象查询*/public List getallByObject(Stu s)List arr=null;try String hql=from Stu as s where s=:stuentity;/或者/String hql=from Stu as s where s.SId=:stuentity;Query query=this.GetSession().createQuery(hql);query.setEntity(stuentity, s);arr=query.list(); catch (HibernateException e) throw e;finallythis.CloseSession();return arr;/* 模糊查询*/public List getallQueryLike(String name)List arr=null;try String hql=from Stu as s where s.SName like :name;Query query=this.GetSession().createQuery(hql);query.setString(name, %+name+%);/不能/query.setString(name, %+name+%);arr=query.list(); catch (HibernateException e) throw e;finallythis.CloseSession();return arr;/* 统计函数*/public int CountStu()int count=0;try String hql=select count(*) from Stu;Query query=this.GetSession().createQuery(hql);count=(Integer) query.uniqueResult(); catch (HibernateException e) throw e;finallythis.CloseSession();return count;finallythis.CloseSession();/* 使用HQL全查询*/public List getallbyHQL()List arr=null;try String hql=from Stu;Query query=this.GetSession().createQuery(hql);arr=query.list(); catch (HibernateException e) throw e;finallythis.CloseSession();return arr;/* 根据主键查询*/public Stu getbyID(int id)Stu stu=null;try stu=(Stu) this.GetSession().get(Stu.class, id); catch (HibernateException e) throw e;finallythis.CloseSession();return stu;/* 根据对象属性查询(使用Query)*/public List getbyPropertyQuery(String name)List arr=null;try /这里不能像SQL语一样select * from Stu where SName=:name,这是不对的。/ Query query=this.GetSession().createQuery(from Stu where SName=:name);/ query.setString(name, name);/或者Query query=this.GetSession().createQuery(from Stu where SName=?);query.setString(0, name);arr=query.list(); catch (HibernateException e) throw e;finallythis.CloseSession();return arr;/* 根据对象属性查询(使用Criteria)*/public List getbyPropertyCriteria(String name)List arr=null;try Criteria cri=this.GetSession().createCriteria(Stu.class);Criterion c1=Expression.eq(SName, name);cri.add(c1);arr=cri.list(); catch (HibernateException e) throw e;finallythis.CloseSession();return arr;/* 查询部分属性*/public List getProperty()List arr=new ArrayList();try String hql=select s.SName,s.SSex from Stu as s;Query query=this.GetSession().createQuery(hql);List list=query.list();Iterator iter=list.iterator();while(iter.hasNext()Object obj=(Object) iter.next();Stu s=new Stu();s.setSName(obj0.toString();s.setSSex(obj1.toString();arr.add(s); catch (HibernateException e) this.CloseSession();return arr;/* 查询一个属性*/public List getoneProperty()List arr=new ArrayList();try String hql=select s.SName from Stu as s;Query query=this.GetSession().createQuery(hql);Iterator iter=query.iterate();while(iter.hasNext()Object obj=(Object) iter.next();Stu s=new Stu();s.setSName(obj.toString();arr.add(s); catch (HibernateException e) this.CloseSession();return arr;/*查询一个对象一个属性值*/public Object getonlyProprotyValue(int s_id)Object obj=null;try String hql=select s.SName from Stu as s where s.SId=?;Query query=this.GetSession().createQuery(hql);query.setInteger(0, s_id);obj=query.uniqueResult(); catch (HibernateException e) throw e;finallythis.CloseSession();return obj;/* SQL查询*/public List getallBYSQL()List arr=null;try String sql=select c.* from stu as c;SQLQuery sqlquery=this.GetSession().createSQLQuery(sql);sqlquery.addEntity(c,Stu.class);arr=sqlquery.list(); catch (HibernateException e) throw e;finallythis.CloseSession();return arr;/* 根据对象查询*/public List getallByObject(Stu s)List arr=null;try String hql=from Stu as s where s=:stuentity;/或者/String hql=from Stu as s where s.SId=:stuentity;Query query=this.GetSession().crea
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 护理区设计理念及要求
- 研究生院年终总结
- 预应力砼现浇箱梁施工质量通病及预防措施
- 树立正确的价值观汇报
- 事物的普遍联系
- 事故安全警示教育培训课件
- 血液透析患者导管护理
- 荨麻疹患儿的护理
- 物业园林部年度工作总结
- 门诊接种工作汇报
- 道亨铁塔长短腿基础配置系统-操作说明
- 秋冬季呼吸道传染病预防知识讲座课件
- 小学科学苏教四年级上册1单元动物大家族2《鱼类》教案
- 团队协作的五大障碍课件
- 一氧化碳中毒急救PPT课件(PPT 43页)
- JIS G4305-2021 冷轧不锈钢板材、薄板材和带材
- 计算机专业英语(第二版)整本书课件完整版电子教案(最新)
- 多晶硅还原装置操作规程
- 复旦大学大学物理热学课件Heat-Ch1-partI
- (完整版)高中物理光学知识点总结
- 履带-轮式爬楼梯电动轮椅设计【带图纸】
评论
0/150
提交评论