Ò»¸öʵÏÖÁ˺ÍÊý¾Ý¿â´ò½»µÀµÄÔ´Îļþ£¨×é×°sqlÓï¾ä°æ£©
package com.itcast.service.base;
import java.util.LinkedHashMap;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.itcast.util.QueryResult;
/**
* Õë¶ÔËùÓÐʵÌåbeanµÄÒ»¸ö³éÏóÀ࣬ËùÓеÄʵÌåbean°üÀ¨ProductType,ProductµÈµÈ
* @author lucky
*
*/
@Transactional
public abstract class DaoSupport implements DAO {
@PersistenceContext protected EntityManager em;
//µ÷ÓÃÏÂÃæµÄpublic <T> void delete(Class<T> entityClass,Object[] entityids·½·¨
public <T> void delete(Class<T> entityClass,Object entityid) {
delete(entityClass,new Object[]{entityid});
}
public <T> void delete(Class<T> entityClass,Object[] entityids) {
for(Object id:entityids){
em.remove(em.getReference(entityClass, id));
}
}
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)//˵Ã÷ÔÚÖ´Ðи÷½·¨µÄʱºò²»ÐèÒª½øÐÐÊÂÎñ´¦Àí
public <T> T find(Class<T> entityClass, Object entityid) {
return em.find(entityClass, entityid);
}
/**
* ¿ÉÒÔ×Ô¶¯¹ÜÀïÖ÷¼üidµÄÉú³É£¬µ«Ç°ÌáÊÇidÊÇ×Ô¶¯Éú³ÉµÄ
* ÈôidÊÇuuidµÄ»°£¬jpa¾Í²»Ö§³Ö×Ô¶¯¹ÜÀíÖ𽥵ŦÄÜ£¬×ÓÀà¾Í±ØÐëÖØÐ´¸Ã·½·¨£¬ÊÖ¶¯Ìí¼ÓÖ÷¼ü
*/
public void save(Object entity) {
em.persist(entity);
}
public void update(Object entity) {
em.merge(entity);
}
@SuppressWarnings("unchecked")
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
/**
* ²éѯµÄÖÕ¼«×îÇ¿°æ£¬¼È¿ÉÒÔ·ÖÒ³£¬ÓÖ¿ÉÒÔ°´Ðò²éѯ£¬»¹¿ÉÒÔÓвéѯÌõ¼þ£¬ÆäËûµÄ²éѯ¶¼Ê¹ÓÃÕâ¸ö²éѯ·½·¨
* orderby Óï¾ä¸ñʽ£ºorder by key1 asc
Ïà¹ØÎĵµ£º
1¡¢Óëgroup by´îÅäʹÓõĺ¯Êý
ÔÚÊý¾Ý¿âÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃGROUP BYº¯Êý°ÑÊý¾Ý×éºÏÔÚÒ»Æð£¬´Ó¶ø»ñµÃ×ܼÆÐÅÏ¢¡£¿ÉÒ԰Ѵ˹¦ÄÜ¿´³ÉÊÇÒ»ÖÖµ±Êý¾Ý´ÓÊý¾Ý¿âÖзµ»ØÊ±°ÑÏàͬÀàÐ͵ÄÐÅÏ¢¼¯Öе½Ò»ÆðµÄÄÜÁ¦¡£ÏÂÃæ¸ø³öÁËÍêÕûÁÐ±í¡£
avg([distinct]column_name)
ÇóËùÓйÍԱнˮµÄƽ¾ùÖµ¡£
select AVG(emp_salary)
from employee;
ÇóÈ¡c ......
Sql´úÂë
--²ÉÓÃSQLÓï¾äʵÏÖsql2005ºÍExcel Êý¾ÝÖ®¼äµÄÊý¾Ýµ¼Èëµ¼³ö£¬ÔÚÍøÉÏÕÒÀ´Ò»--Ï£¬ÊµÏÖ·½·¨ÊÇÕâÑùµÄ£º
--Excel---->SQL2005 µ¼È룺
select * into useinfo from O ......
1 £¬¶ÔÓÚÈÕÆÚ×Ö¶Î×Ö¶Î
access±íʾΪ£º#1981-28-12#
SQLSERVER2000±íʾΪ£º''1981-02-12''
2,SQLÓï¾äÇø±ð£¬select ,update ÔÚ¶Ôµ¥±í²Ù×÷ʱ¶¼²î²»¶à£¬
µ«¶à±í²Ù×÷ʱupdateÓï¾äµÄÇø±ðACCESSÓëSQLSERVERÖеÄUpdateÓï¾ä¶Ô±È:
SQLSERVERÖиüжà±íµÄUpdateÓï¾ä:
Update Tab1
SET a.Name = b.Name
from Tab1 a,Tab2 b
Whe ......
1.´ò¿ªSQL server enterprise mananger “ÆóÒµ¹ÜÀíÆ÷”
ÔÚÄãÒªµ¼³öµÄSQLÊý¾Ý¿âÉÏÊó±êÓÒ¼ü²Ëµ¥£ºËùÓÐÈÎÎñ-¡·µ¼³öÊý¾Ý
2.»Ø³öÏÖÒ»¸öµ¼³öÏòµ¼´°¿Ú¡£
Ñ¡Ôñ±»µ¼³öµÄÊý¾ÝÔ´£¬ÎªÄã¸Õ²ÅËùÑ¡ÔñµÄÊý¾Ý¿â£¬Èç¹û·¢ÏÖ²»¶ÔÓ¦×ÔÐÐÐ޸ġ£
3.½øÈëµ¼³öµ½Ä¿±êÊý¾ÝÔ´µÄÑ¡Ôñ£¬ÕâÀïÎÒÃÇҪת³ÉACCESSµÄÊý¾Ý¿â¡£×¢ÒâÑ¡ÔñÊý¾ÝÔ´ÀàÐÍÎ ......