当前位置:首页 » 编程语言 » hibernate的sql查询

hibernate的sql查询

发布时间: 2022-08-30 01:42:43

1. ssh使用hibernate进行sql查询问题

as col_0_0_这是hibernate内部框架实现,也就是hibernate.dialect。他会把你hql转换sql,主要是根据不同数据库做变化,省去你修改的麻烦。

List<Score_detail> sdList = (List<Score_detail>) getSession().createQuery(hql).list();

这样查询出来,然后遍历list,后用sd.getDep...就能取得你要的字段。

2. Hibernate 有哪几种查询数据的方式

HIbernate主要有三种查询方式HQL、QBC、SQL:

1).HQL(Hibernate Query Language):hibernate数据查询语言;

2).QBC(Query By Criteria):规则查询

3).SQL:原生的SQL语句(较为复杂的情况下使用)

想要详细了解的可以看一下下面的几篇文章:

  • QBC数据查询

  • HQL单表查询

  • HQL多表查询

希望对你有所帮助~

3. 在hibernate运用sql查询

基础不扎实 list map等使用iterator 不是很简单?
Iterator it=list.iterator();
while(it.hasNext()){
Permit permit=(Permit)it.next();
System.out.println(permit.getName());
}
如果在jsp里面 直接用<s:iterator>标签

4. hibernate使用sql查询

给你一个我写的例子:
public List<Statistics> statistics(){
String sql="select "+
"sum(case when (t.type_code=3) then 1 else 0 end),"+
"sum(case when (t.type_code=5) then 1 else 0 end),"+
"sum(case when (t.type_code=8) then 1 else 0 end),"+
"sum(case when (t.type_code=0) then 1 else 0 end),"+
"sum(case when (t.type_code=6) then 1 else 0 end),"+
"sum(case when (t.type_code=9) then 1 else 0 end),"+
"count(*)"+
"from cs_cust_complaint_data t where t.from_flag='2'";
List<Statistics> stal = new ArrayList<Statistics>();
SQLQuery query = getSession().createSQLQuery(sql);
Object[] obj = (Object[])query.uniqueResult();
BigDecimal b0 = (BigDecimal)obj[0];
BigDecimal b1 = (BigDecimal)obj[1];
BigDecimal b2 = (BigDecimal)obj[2];
BigDecimal b3 = (BigDecimal)obj[3];
BigDecimal b4 = (BigDecimal)obj[4];
BigDecimal b5 = (BigDecimal)obj[5];
BigDecimal b6 = (BigDecimal)obj[6];
Double zs = b6.doubleValue();
DecimalFormat df=new DecimalFormat("#.00");
stal.add(new Statistics("卷烟营销", b0.longValue(),Double.parseDouble(df.format(b0.doubleValue()/zs*100))));
stal.add(new Statistics("专卖法规", b1.longValue(),Double.parseDouble(df.format(b1.doubleValue()/zs*100))));
stal.add(new Statistics("烟叶生产", b2.longValue(),Double.parseDouble(df.format(b2.doubleValue()/zs*100))));
stal.add(new Statistics("政风行风", b3.longValue(),Double.parseDouble(df.format(b3.doubleValue()/zs*100))));
stal.add(new Statistics("人事劳资", b4.longValue(),Double.parseDouble(df.format(b4.doubleValue()/zs*100))));
stal.add(new Statistics("其他咨询", b5.longValue(),Double.parseDouble(df.format(b5.doubleValue()/zs*100))));
return stal;
}

5. hibernate sql 条件查询问题。

可以如下进行查询:
Criteria criteria = session.createCriteria(User.class);
List users = criteria.list();
for(Iterator it = users.iterator(); it.hasNext(); ) {
User user = (User) it.next();
System.out.println(user.getId() +
" /t " + user.getName() +
"/" + user.getAge());
}

6. hibernate sql查询语句

既然你的项目继承了hibernateDaoSupoort,并且是由spring来管理的那么,我想应该实在applicationContext.xml中配置的sessionFactory或者getTemplate来注入数据库连接的,既然如此在hibernateDaoSupport的继承类中可以得到写很多的封装查询、添加、删除操作,只需要把方法加入一个抽象类去实现就好了
不过你要通过sql语句去实现的话
因为已经注入了数据库连接到hibernateDaoSupport中.所以你也继承到了两个数据库连接方法getSession() 和 getHibernateTemplate()
直接用就可以了

热点内容
app什么情况下找不到服务器 发布:2025-05-12 15:46:25 浏览:708
php跳过if 发布:2025-05-12 15:34:29 浏览:463
不定时算法 发布:2025-05-12 15:30:16 浏览:126
c语言延时1ms程序 发布:2025-05-12 15:01:30 浏览:162
动物园灵长类动物配置什么植物 发布:2025-05-12 14:49:59 浏览:728
wifi密码设置什么好 发布:2025-05-12 14:49:17 浏览:143
三位数乘两位数速算法 发布:2025-05-12 13:05:48 浏览:391
暴风影音缓存在哪里 发布:2025-05-12 12:42:03 浏览:537
access数据库exe 发布:2025-05-12 12:39:04 浏览:623
五开的配置是什么 发布:2025-05-12 12:36:37 浏览:359