由将SQL查询结果转化为pojo的想到的
今天在网上上看见一篇“将SQL查询结果转化为pojo对象的”博客,博主自定义做了一个类如下:
import java.lang.reflect.Field;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.property.ChainedPropertyAccessor;
import org.hibernate.property.PropertyAccessor;
import org.hibernate.property.PropertyAccessorFactory;
import org.hibernate.property.Setter;
import org.hibernate.transform.ResultTransformer;
/**
* 完成native sql查询数据(数组)到pojo对象的转化
* @author warison
*
* Oct 26, 2009
*/
public class PojoTransformer implements ResultTransformer {
private static final long serialVersionUID = 1L;
private Class<? extends BaseModel> resultClass;
private Setter[] setters;
private PropertyAccessor propertyAccessor;
public PojoTransformer(Class<? extends BaseModel> resultClass) {
if(resultClass==null)
throw new IllegalArgumentException("resultClass cannot be null");
this.resultClass = resultClass;
propertyAccessor = new ChainedPropertyAccessor(new PropertyAccessor[] { PropertyAccessorFactory.getPropertyAccessor(resultClass,null), PropertyAccessorFactory.getPropertyAccessor("field")});
}
//结果转换时,HIBERNATE调用此方法
&n
相关文档:
1.如何创建数据库
CREATE DATABASE student
2.如何删除数据库
DROP DATABASE student
3.如何备份数据库到磁盘文件
BACKUP DATABASE student to disk=´c:S4.bak´
4.如何从磁盘文件还原数据库
RESTORE DATABASE studnet from DISK = ´c:S4.bak´
5.怎样创建表?
CREATE TABLE Students (
&n ......
摘自http://blog.sina.com.cn/zhm85
SQL语句截取时间,只显示年月日(2004-09-12)
select CONVERT(varchar, getdate(), 120 )
‘getdate()’改为时间字段名‘createtime’
再重命名新加列(Select Name AS UName from Users)
例如 select convert(varchar(11),createtime,120) as Ndate fro ......
转自:http://hi.baidu.com/arslong/blog/item/b23307e76252342cb8382001.html
Item01
连接字符串中常用的声明有:
服务器声明:Data Source
、Server
和Addr
等。
数据库声明:Initial Catalog
和DataBase
等。
集成Windows
账号的安全性声明:Integrated
Security
和Trusted_Connection
等。
使用数据库 ......
摘要
对于SQL Server中的约束,想必大家并不是很陌生。但是约束中真正的内涵是什么,并不是很多人都很清楚的。本文以详细的文字来介绍了什么是约束,以及如何在数据库编程中应用和使用这些约束,来达到更好的编程效果。(本文部分内容参考了SQL Server联机手册)
内容
数据完整性分类
实体完整性
&nb ......
http://blog.csdn.net/fenglibing/archive/2007/10/24/1841537.aspx
1、将一个表中的内容拷贝到另外一个表中
insert into testT1(a1,b1,c1) select a,b,c from test;
insert into testT select * from test; (前提是兩個表的結構完全相同)
insert into notebook(id,title,content)
se ......