lqxue

          常用鏈接

          統計

          book

          tools

          最新評論

          #

          mysql 行變列的例句

          select distinct item.reportoid, item.lineoid,  item.accountoid, sun.amount, mon.amount, tue.amount, wes.amount, thur.amount, fri.amount, sat.amount
          from expenseitem item
          left join (select reportoid, accountoid, lineoid, amount, itemDate from expenseitem
           where itemDate = '2007-11-04' ) sun
           on item.reportoid = sun.reportoid and
            item.accountoid = sun.accountoid and
            item.lineoid = sun.lineoid and
            item.itemDate = sun.itemDate
          left join (select reportoid, accountoid,  lineoid, amount, itemDate from expenseitem
           where itemDate = adddate('2007-11-04', 1) ) mon
           on item.reportoid = mon.reportoid and
            item.accountoid = mon.accountoid and
            item.lineoid = mon.lineoid and
            item.itemDate = mon.itemDate
          left join (select reportoid, accountoid,  lineoid,amount, itemDate from expenseitem
           where itemDate = adddate('2007-11-04', 2)) tue
           on item.reportoid = tue.reportoid and
            item.accountoid = tue.accountoid and
            item.lineoid = tue.lineoid and
            item.itemDate = tue.itemDate
          left join (select reportoid, accountoid,  lineoid,amount, itemDate from expenseitem
           where itemDate = adddate('2007-11-04', 3)  ) wes
           on item.reportoid = wes.reportoid and
            item.accountoid = wes.accountoid and
            item.lineoid = wes.lineoid and
            item.itemDate = wes.itemDate
          left join (select reportoid, accountoid,  lineoid,amount, itemDate from expenseitem
           where itemDate = adddate('2007-11-04', 4)  ) thur
           on item.reportoid = thur.reportoid and
            item.accountoid = thur.accountoid and
            item.lineoid = thur.lineoid and
            item.itemDate = thur.itemDate
          left join (select reportoid, accountoid,  lineoid,amount, itemDate from expenseitem
           where itemDate = adddate('2007-11-04', 5)  ) fri
           on item.reportoid = fri.reportoid and
            item.accountoid = fri.accountoid and
            item.lineoid = fri.lineoid and
            item.itemDate = fri.itemDate
          left join (select reportoid, accountoid,  lineoid,amount, itemDate from expenseitem
           where itemDate = adddate('2007-11-04', 6) ) sat
           on item.reportoid = sat.reportoid and
            item.accountoid = sat.accountoid and
            item.lineoid = sat.lineoid and
            item.itemDate = sat.itemDate
          where item.reportoid = 3712
          order by reportoid, accountoid;

          posted @ 2008-07-08 10:52 lqx 閱讀(650) | 評論 (0)編輯 收藏

          sql server REVERSE ASCII

          SELECT REVERSE('abc') AS Expr1


          SELECT ascii('c') AS Expr1 取asc碼

          posted @ 2008-07-08 09:29 lqx 閱讀(185) | 評論 (0)編輯 收藏

          sql 在查詢時,如果為空的時,如何用默認值代替空

          COALESCE(a.end_,now())

          posted @ 2008-07-04 17:31 lqx 閱讀(751) | 評論 (0)編輯 收藏

          如何用一條sql語句,返回某個月的所有天數

          select DATE_ADD(date('2008-01-01'),INTERVAL days DAY) days from (select 0 days union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9 union select 10 union select 11 union select 12 union select 13 union select 14 union select 15 union select 16 union select 17 union select 18 union select 19 union select 20 union select 21 union select 22 union select 23 union select 24 union select 25 union select 26 union select 27 union select 28 union select 29 union select 30 union select 31) as b

          posted @ 2008-07-04 17:29 lqx 閱讀(658) | 評論 (0)編輯 收藏

          wsdl 祥解

          http://www.tutorialspoint.com/wsdl/index.htm

          posted @ 2008-07-04 10:48 lqx 閱讀(266) | 評論 (0)編輯 收藏

          very cool tutorialspoint

          http://www.tutorialspoint.com/

          posted @ 2008-07-04 10:47 lqx 閱讀(275) | 評論 (0)編輯 收藏

          兩段式提交

          通過使用某種協議進行通信來完成分布式事務,被稱為兩段式提交。從名字上看,您可能已經知道有兩個階段:

           

          • 第一個階段,即預提交
            • 事務協調器給每個事務管理器發送準備操作的信號。
            • 事務管理器將操作(通常是數據更新)步驟(或細節)寫入事務日志。如果失敗,事務管理器使用這些步驟重復操作。
            • 事務管理器本地創建事務并通知資源管理器對資源(例如,數據庫或消息服務器)執行操作。
            • 資源管理器執行操作并向事務管理器報告成功(準備提交信號)或失?。蕚浠貪L)。
            • 資源管理器等待事務管理器進一步的指令。
            • 事務管理器向事務協調器報告成功或失敗。
          • 第二階段,即提交階段:在第二階段中,第一階段的結果將傳送給所有事務管理器。如果任何事務管理器報告失敗,所有的事務參與者都必須回滾。
            • 事務協調器讓所有事務管理器提交(或回滾)。
            • 所有事務管理器將提交或回滾信息傳遞給其資源管理器。
            • 資源管理器將成功或失敗提示返回給事務管理器。
            • 事務管理器向事務協調器報告成功或失敗。

          posted @ 2008-07-04 10:15 lqx 閱讀(495) | 評論 (0)編輯 收藏

          Hibernate二級緩存全攻略

          【IT168 技術文檔】很多人對二級緩存都不太了解,或者是有錯誤的認識,我一直想寫一篇文章介紹一下hibernate的二級緩存的,今天終于忍不住了。
          我的經驗主要來自hibernate2.1版本,基本原理和3.0、3.1是一樣的,請原諒我的頑固不化。

              hibernate的session提供了一級緩存,每個session,對同一個id進行兩次load,不會發送兩條sql給數據庫,但是session關閉的時候,一級緩存就失效了。

              二級緩存是SessionFactory級別的全局緩存,它底下可以使用不同的緩存類庫,比如ehcache、oscache等,需要設置hibernate.cache.provider_class,我們這里用ehcache,在2.1中就是
          hibernate.cache.provider_class=net.sf.hibernate.cache.EhCacheProvider
          如果使用查詢緩存,加上
          hibernate.cache.use_query_cache=true

          緩存可以簡單的看成一個Map,通過key在緩存里面找value。

          Class的緩存
              對于一條記錄,也就是一個PO來說,是根據ID來找的,緩存的key就是ID,value是POJO。無論list,load還是 iterate,只要讀出一個對象,都會填充緩存。但是list不會使用緩存,而iterate會先取數據庫select id出來,然后一個id一個id的load,如果在緩存里面有,就從緩存取,沒有的話就去數據庫load。假設是讀寫緩存,需要設置:

          <cache usage="read-write"/>

              如果你使用的二級緩存實現是ehcache的話,需要配置ehcache.xml
          <cache name="com.xxx.pojo.Foo" maxElementsInMemory="500" eternal="false" timeToLiveSeconds="7200" timeToIdleSeconds="3600" overflowToDisk="true" />

              其中eternal表示緩存是不是永遠不超時,timeToLiveSeconds是緩存中每個元素(這里也就是一個POJO)的超時時間,如果 eternal="false",超過指定的時間,這個元素就被移走了。timeToIdleSeconds是發呆時間,是可選的。當往緩存里面put 的元素超過500個時,如果overflowToDisk="true",就會把緩存中的部分數據保存在硬盤上的臨時文件里面。

              每個需要緩存的class都要這樣配置。如果你沒有配置,hibernate會在啟動的時候警告你,然后使用defaultCache的配置,這樣多個class會共享一個配置。
          當某個ID通過hibernate修改時,hibernate會知道,于是移除緩存。

              這樣大家可能會想,同樣的查詢條件,第一次先list,第二次再iterate,就可以使用到緩存了。實際上這是很難的,因為你無法判斷什么時候是第一 次,而且每次查詢的條件通常是不一樣的,假如數據庫里面有100條記錄,id從1到100,第一次list的時候出了前50個id,第二次 iterate的時候卻查詢到30至70號id,那么30-50是從緩存里面取的,51到70是從數據庫取的,共發送1+20條sql。所以我一直認為 iterate沒有什么用,總是會有1+N的問題。

              (題外話:有說法說大型查詢用list會把整個結果集裝入內存,很慢,而iterate只select id比較好,但是大型查詢總是要分頁查的,誰也不會真的把整個結果集裝進來,假如一頁20條的話,iterate共需要執行21條語句,list雖然選擇 若干字段,比iterate第一條select id語句慢一些,但只有一條語句,不裝入整個結果集hibernate還會根據數據庫方言做優化,比如使用mysql的limit,整體看來應該還是 list快。)

              如果想要對list或者iterate查詢的結果緩存,就要用到查詢緩存了


          posted @ 2008-07-03 13:29 lqx 閱讀(161) | 評論 (0)編輯 收藏

          http://www.w3school.com.cn

          一個b好的介紹w3c的網站。
          http://www.w3school.com.cn

          posted @ 2008-07-02 13:25 lqx 閱讀(774) | 評論 (1)編輯 收藏

          一種實現數據庫連接池的方法

          http://webservices.ctocio.com.cn/wsjavtec/62/7690562.shtml

          posted @ 2008-06-26 15:45 lqx 閱讀(212) | 評論 (0)編輯 收藏

          僅列出標題
          共18頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 Last 
          主站蜘蛛池模板: 鄂州市| 郑州市| 溧阳市| 武穴市| 福安市| 高尔夫| 天门市| 北京市| 宁城县| 华安县| 剑阁县| 泾阳县| 靖边县| 蓬安县| 天等县| 峡江县| 长岭县| 临汾市| 涞源县| 博乐市| 芒康县| 南丹县| 界首市| 化隆| 荔浦县| 枞阳县| 宜兰县| 佛山市| 探索| 双柏县| 象山县| 会泽县| 朝阳县| 鄢陵县| 搜索| 综艺| 海城市| 宝清县| 常熟市| 稷山县| 开封县|