Hibernate的原生SQL查询
折腾了我半天终于搞定了
参考了这个文章:http://doc.javanb.com/hibernate-reference-3-2-0-zh/ch16.html
final static String querySql = "select {enterprise.*}, {dict.*} ,{balancd.*}, {weightinfo.*} "
+ "from weight_info weightinfo left outer join t_dict dict on {weightinfo}.productcode={dict}.code join "
+ "t_balancecode {balancd} on {weightinfo}.balancecode={balancd}.balancecode join t_enterprise enterprise "
+ "on {enterprise}.id={balancd}.enterpriseid where "
+ " {weightinfo}.operdate>TO_TIMESTAMP('2009-11-2 04:12:32.0', 'yyyy-mm-dd hh24:mi:ssxff')";
public List loadByQuerySql(final String querySql, final Map params) {
try {
return (List) getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
// Connection c= session.connection();
Query query = session.createSQLQuery(querySql)
.addEntity("weightinfo",WeightInfo.class)
.addEntity("dict",Dict.class)
.addEntity("balancd",BalanceCode.class)
.addEntity("enterprise",Enterprise.class);
// fillParams(query,params);
return query.list();
}
});
} catch (HibernateException e) {
e.printStackTrace();
}
return new ArrayList();
}
如果不是全部参与的table都返回值,那么
public Object doInHibern
相关文档:
1不用在sql语句使用系统默认的保留关键字
2尽量用exists 和 not exists 代替 in 和 not in
这条在sql2005之后,在索引一样,统计信息一样的情况下,exists ,in效果是一样的。
以AdventureWorks数据库为例,查询在H ......
在SQL UPDATE语句中,对换两个变量的值,不需要临时变量。=右侧的值在整个UPDATE语句中都是一致的;所有的更新同时发生,而不是一个接着一个发生。
例如:
UPDATE offenceTeam
SET goalShooter=wingAttack,
& ......
虽然说ASP.NET属于安全性高的脚本语言,但是也经常看到ASP.NET网站由于过滤不严造成注射.由于ASP.NET基本上配合MMSQL数据库架设 如果权限过大的话很容易被攻击. 再者在网络上找不到好的ASP.NET防注射脚本,所以就自己写了个. 在这里共享出来旨在让程序员免除SQL注入的困扰.
我写了两个版本,VB.NET和C#版本方便不同程序间使用 ......
SQL数据恢复软件 Log Explorer for SQL Server v4.0
log explorer使用的几个问题
1)对数据库做了完全 差异 和日志备份
备份时选用了删除事务日志中不活动的条目
再用Log explorer打试图看日志时
提示No log recorders found that match the filter,would you like to view unfiltered ......