Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

hibernate sql²éѯ list


±¾ÎÄתÔØ: http://hi.baidu.com/%D2%BB%C6%F0%C8%A5%CC%DF%C7%F2/blog/item/802027355899fe83a61e12ee.html
ʹÓÃSQLQuery
¶ÔÔ­ÉúSQL²éѯִÐеĿØÖÆÊÇͨ¹ýSQLQuery½Ó¿Ú½øÐеģ¬Í¨¹ýÖ´ÐÐSession.createSQLQuery
()
»ñÈ¡Õâ¸ö½Ó¿Ú¡£×î¼òµ¥µÄÇé¿öÏ£¬ÎÒÃÇ¿ÉÒÔ²ÉÓÃÒÔÏÂÐÎʽ£º
List
cats
=
sess.createSQLQuery
(
"
select * from cats
"
).addEntity(Cat.
class
).list
();
Õâ¸ö²éѯָ¶¨ÁË:
SQL²éѯ×Ö·û´®
²éѯ·µ»ØµÄʵÌå
ÕâÀ½á¹û¼¯×Ö¶ÎÃû±»¼ÙÉèΪÓëÓ³ÉäÎļþÖÐÖ¸Ã÷µÄ×Ö¶ÎÃûÏàͬ¡£¶ÔÓÚÁ¬½ÓÁ˶à¸ö±íµÄ²éѯ£¬Õâ¾Í¿ÉÄÜÔì³ÉÎÊÌ⣬ÒòΪ¿ÉÄÜÔÚ¶à¸ö±íÖгöÏÖͬÑùÃû×ÖµÄ×ֶΡ£ÏÂ
ÃæµÄ·½·¨¾Í¿ÉÒÔ±ÜÃâ×Ö¶ÎÃûÖظ´µÄÎÊÌâ:
List
cats
=
sess.createSQLQuery
(
"
select {cat.*} from cats cat
"
).addEntity(
"
cat
"
, Cat.
class
).list
();
Õâ¸ö²éѯָ¶¨ÁË:
SQL²éѯÓï¾ä£¬Ëü´øÒ»¸öռλ·û£¬¿ÉÒÔÈÃHibernateʹÓÃ×ֶεıðÃû.
²éѯ·µ»ØµÄʵÌ壬ºÍËüµÄSQL±íµÄ±ðÃû.
addEntity()·½·¨½«SQL±íµÄ±ðÃûºÍʵÌåÀàÁªÏµÆðÀ´£¬²¢ÇÒÈ·¶¨²éѯ½á¹û¼¯µÄÐÎ̬¡£
addJoin()·½·¨¿ÉÒÔ±»ÓÃÓÚÔØÈëÆäËûµÄʵÌåºÍ¼¯ºÏµÄ¹ØÁª.
List
cats
=
sess.createSQLQuery
(
"
select {cat.*}, {kitten.*} from cats cat, cats kitten where
kitten.mother = cat.id
"
)
.addEntity(
"
cat
"
, Cat.
class
)
.addJoin(
"
kitten
"
,
"
cat.kittens
"
)
.list
();
Ô­ÉúµÄSQL²éѯ¿ÉÄÜ·µ»ØÒ»¸ö¼òµ¥µÄ±êÁ¿Öµ»òÕßÒ»¸ö±êÁ¿ºÍʵÌåµÄ½áºÏÌå¡£
Double max
=
(Double)
sess.createSQLQuery
(
"
select max(cat.weight)
as maxWeight from cats cat
"
)
.addScalar(
"
maxWeight
"
, Hibernate.DOUBLE);
.uniqueResult();
³ý´ËÖ®Í⣬Ä㻹¿ÉÒÔÔÚÄãµÄhbmÎļþÖÐÃèÊö½á¹û¼¯Ó³ÉäÐÅÏ¢£¬ÔÚ²éѯÖÐʹÓá£
List
cats
=
sess.createSQLQuery
(
"
select {cat.*}, {kitten.*} from cats cat, cats kitten where
kitten.mother = cat.id
"
)
.setResultSetMapping(
"
catAndKitten
"
)
.list
();
ÃüÃûSQL²éѯ
¿ÉÒÔÔÚÓ³ÉäÎĵµÖж¨Òå²éѯµÄÃû×Ö,È»ºó¾Í¿ÉÒÔÏóµ÷ÓÃÒ»¸öÃüÃûµÄHQL²éѯһÑùÖ±½Óµ÷ÓÃÃüÃûSQL²éѯ.ÔÚÕâÖÖÇé¿öÏÂ,ÎÒÃDz»
ÐèÒ


Ïà¹ØÎĵµ£º

AccessÓëSql ServerÖ®ASP´úÂë±È½Ï

ºǫ́Êý¾Ý¿â£º
[Microsoft Access]
Óë
[Microsoft Sql Server]
¸ü»»Ö®ºó£¬ASP´úÂëӦעÒâÒªÐ޸ĵÄһЩµØ·½£º
[Ò»]Á¬½ÓÎÊÌ⣨¾ÙÀý)
[Microsoft Access]
constr = "DBQ=c:\data\clwz.mdb; DRIVER={Microsoft Access Driver (*.mdb)}"
[Microsoft Sql Server]
constr = "DRIVER={SQL Server};SERVER=host;DATA ......

Ò»²½Ò»²½Ñ§Linq to sql£¨ËÄ£©£º²éѯ¾ä·¨


select
 
ÃèÊö£º²éѯ¹Ë¿ÍµÄ¹«Ë¾Ãû¡¢µØÖ·ÐÅÏ¢
²éѯ¾ä·¨£º
var ¹¹½¨ÄäÃûÀàÐÍ1 = from c in ctx.Customers
                      select new
    ......

Èí¼þϵͳÐÔÄÜÓÅ»¯²ßÂÔSQLÓÅ»¯

    ¶øÕâһƪÖУ¬ÎÒÃǾÍΧÈÆSQLÓÅ»¯À´¿ªÊ¼Õâ´Î½²½â£¬ÎªÊ²Ã´µÚÒ»½²ÒªËµSQLÓÅ»¯£¿ÒòΪÎÒÈÏΪÕâÊdzÌÐòÔ±µÄ»ù±¾¹¦£¬¶øÇÒÒ²ÊÇÎÒÃDZØÐëҪȥÕÆÎյģ¬ËäÈ»ÄãдµÄ SQLÓï¾äÄÜÍê³ÉÏàÓ¦µÄ¹¦ÄÜ£¬µ«ÊÇÄãÊÇ·ñ¿¼ÂǹýÕâЩÓï¾äÅöµ½º£Á¿Êý¾Ý»òÕß±©Á¦·ÃÎÊʱ»á²»»á´øÀ´Ð§ÂʵĴó·ù¶ÈµÄ¼õÂý£¿Ò²ÐíºÜ¶à³ÌÐòÔ±ºÍÎÒÒ»ÑùÔÚÅöµ½ÏµÍ³ÏìÓ¦Ê ......

¡¾×ª¡¿+¡¾Ô­¡¿SQL Server ÈÕÆÚº¯Êý£ºÄ³ÌìÊÇÐÇÆÚ¼¸

ÒªµÃµ½Ä³Ò»ÌìÊÇÐÇÆÚ¼¸£¬ÐèÒªÓõ½ SQL Server ÖеÄÈÕÆÚº¯Êý£ºdatename()¡£ ½ñÌìÊÇÐÇÆÚ¼¸£¬Àý×Ó 1£º 1: set language N'English'
2: select datename(weekday, getdate())
3: 
4: Wednesday
½ñÌìÊÇÐÇÆÚ¼¸£¬Àý×Ó 2£º

1: set language N'Simplified Chinese'
......

sql ÓαêµÄʹÓÃ

Ò»¸öÀý×Ó£º´Ótszl±íÖвé³öÊý¾Ý£¬¸ù¾Ýcs×ֶεÄÖµ¾ö¶¨ÍùBOOK_SERIAL±íÖвåÈ뼸ÐÐÊý¾Ý¡£
declare @num int
declare @id varchar(60)
declare @classbm varchar(60)
set @classBm='101'
declare id cursor for select id,cs from  [tszl]
open id
fetch next from id into @id,@num
while @@fetch_status!=-1
&nb ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ