由将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
相关文档:
--测试数据
create table table1(AID int,NAME nvarchar(20))
create table table2 (BID int,NUMBER nvarchar(20))
insert into table1 select 1,'Tom' union all
select 2,'Jim'
insert into table2 select 1,20 union all
select 1,30
--函数
create function F_Str(@ID int)
returns nvarchar(100)
as
begin
......
SQL基本语句
一. SQL的四条最基本的数据操作语句为Insert,Select,Update和Delete。
二.首先我们使用CREATE TABLE语句来创建一个表。DDL语句对数据库对象如表、列和视进行定义。它们并不对表中的行进行处理,这是因为DDL语句并不处理数据库中实际的数据。这些工作由另一 ......
摘自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 ......
直接restore或附加应该是不行的, 用脚本+导数据肯定没有问题。
2005转到2000的步骤
1. 生成for 2000版本的数据库脚本
2005 的manger studio
-- 打开"对象资源管理器"(没有的话按F8), 连接到你的实例
-- 右键要转到2000的库
-- 任务
-- 生成脚本
-- 在"脚本向导"的"选择数据库"中, ......
. SQL 命令
这部分包含那些 PostgreSQL 支持的 SQL 命令的信息.这里的 "SQL" 就是该语言通常的含义; 每条命令的与标准有关的兼容性的信息可以在相关的参考页中找到.
Table of Contents
ABORT -- 退出当前事务
ALTER GROUP -- 向组中增加用户或从组中删除用户
ALTER USER -- 改变数据库 ......