posts - 262,  comments - 221,  trackbacks - 0
               摘要: 設置列格式的相關命令  閱讀全文
          posted @ 2008-05-26 23:15 Paul Lin 閱讀(947) | 評論 (0)編輯 收藏
               摘要: 設置標題的相關命令  閱讀全文
          posted @ 2008-05-26 22:54 Paul Lin 閱讀(787) | 評論 (0)編輯 收藏
               摘要: 和執(zhí)行相關的命令  閱讀全文
          posted @ 2008-05-26 22:50 Paul Lin 閱讀(1150) | 評論 (0)編輯 收藏

          如題,Oracle數(shù)據(jù)庫里面有一批記錄,現(xiàn)在我想根據(jù)其中一個叫:txn_date的字段來查詢記錄,在Hbm文件中我配置了該HQL,如下所示:

          <sql-query name="job.getJobByDate">
              select {job.*} from Newsletter_Message job 
               where to_char(:dateType,'yyyy-mm-dd hh24:mi') = 
                     to_char(:jobDate, 'yyyy-mm-dd hh24:mi')
          <return alias="job"
                  class
          ="com.newsletter.domain.job.Job" />
          </sql-query>


          在DAO方法中我使用了Spring的HibernateTemplate,方法如下:

          public List<Job> getJobByDate(final Date jobDate, final String dateType) {
           
          return (List<Job>
            getHibernateTemplate().executeFind(
              
          new HibernateCallback() 

                
          public
           Object doInHibernate(Session session)
                    
          throws HibernateException 
          {
                  Query query 
          = session.getNamedQuery("job.getJobByDate"
          );
                  query.setString(
          "dateType"
          , dateType);
                  query.setDate(
          "jobDate"
          ,jobDate);
                  
          return
           query.list();
                }

           }
          );
          }


          Hibernate生成的SQL語句如下

          select job.TXN_NO as TXN1_5_0_,
                 job.TXN_TYPE 
          as
           TXN2_5_0_,
                 job.TXN_DATE 
          as
           TXN3_5_0_, 
            
          from
           Newsletter_Message job
           
          where to_char(?, 'yyyy-mm-dd hh24:mi'= to_char(?, 'yyyy-mm-dd hh24:mi')


          每次執(zhí)行時,總是拋異常,說:
          org.springframework.dao.DataIntegrityViolationException: Hibernate operation: could not execute query;
          .....
          Caused by: java.sql.SQLException: ORA-01722: invalid number

          我實在不明白為什么會報這個錯誤,難道Hibernate在set date或者set string之前不會對其進行格式的轉換嗎?于是我又換了另外一個HQL語句,在代碼里面提前將Date格式成String,但還是報錯:

          where to_char(dateType,'yyyy-mm-dd hh24:mi') = :strDate

          后來實在沒辦法了,用了一陰招,代碼如下,測試通過,但是覺得這種代碼太丑陋了。

          public List<Job> getJobByDate(final Date jobDate, final String dateType) {
            
          return getHibernateTemplate().executeFind(new HibernateCallback() 
          {
              
          public
           Object doInHibernate(Session session)
                  
          throws HibernateException 
          {

               String strDate 
          =
           DateUtil.convertDateToString(jobDate,
                                      
          "yyyy-MM-dd HH:mm"
          );
              Query query 
          = session.createQuery("from Job job where "

                                  
          + "to_char(" + dateType + ",'yyyy-mm-dd hh24:mi') = '"
                                   
          + strDate + "'");
              
          return (List<Job>
          ) query.list();
              }

            }
          );
          }


          不知道各位能否解析一下上面那個報錯的原因,謝謝先了!

          posted @ 2008-05-22 16:40 Paul Lin 閱讀(2264) | 評論 (0)編輯 收藏

          【1】pfile:初始化參數(shù)文件

          包含了init.ora文件,該文件定義了幾個非常重要的參數(shù):

          ·db_domain:數(shù)據(jù)庫域名
          ·db_name:數(shù)據(jù)庫名
          ·control_files:控制文件的路徑,通常有3個文件
          ·shared_pool_size=共享池的大小
          ·background_dump_dest=后臺進程日志、跟蹤文件路徑
          ·core_dump_dest=操作系統(tǒng)崩潰的日志、跟蹤文件路徑
          ·user_dump_dest=用戶進程的跟蹤文件路徑

          【2】budmp:存放由后臺進程所生成的數(shù)據(jù)庫Alert日志文件和跟蹤文件

          典型的包含了一個.log文件和一個.trc文件。

          打開.log文件我們可以看到里面有很多后臺進程的啟動及運行信息,其中最關鍵的就是加載init.ora文件和起點后臺進程的日志了


          Starting up ORACLE RDBMS Version: 9.2.0.1.0.
          System parameters with non-default values:
            processes                = 150
            timed_statistics         = TRUE
            shared_pool_size         = 50331648
            large_pool_size          = 8388608
            java_pool_size           = 33554432
            control_files            = C:\oracle\oradata\paullin\control01.ctl, C:\oracle\oradata\paullin\control02.ctl, C:\oracle\oradata\paullin\control03.ctl
            db_block_size            = 8192
            db_cache_size            = 25165824
            compatible               = 9.2.0.0.0
            db_file_multiblock_read_count= 16
            fast_start_mttr_target   = 300
            undo_management          = AUTO
            undo_tablespace          = UNDOTBS1
            undo_retention           = 10800
            remote_login_passwordfile= EXCLUSIVE
            db_domain                =
            instance_name            = paullin
            dispatchers              = (PROTOCOL=TCP)
            job_queue_processes      = 10
            hash_join_enabled        = TRUE
            background_dump_dest     = C:\oracle\admin\paullin\bdump
            user_dump_dest           = C:\oracle\admin\paullin\udump
            core_dump_dest           = C:\oracle\admin\paullin\cdump
            sort_area_size           = 524288
            db_name                  = paullin
            open_cursors             = 300
            star_transformation_enabled= FALSE
            query_rewrite_enabled    = FALSE
            pga_aggregate_target     = 25165824
            aq_tm_processes          = 1
          PMON started with pid=2
          DBW0 started with pid=3
          LGWR started with pid=4
          CKPT started with pid=5
          SMON started with pid=6
          RECO started with pid=7
          CJQ0 started with pid=8
          QMN0 started with pid=9

          而.trc文件里面則保存了當前會話的ID


          【3】cdump:存放發(fā)生崩潰的操作系統(tǒng)的系統(tǒng)進程信息

          【4】create:存儲創(chuàng)建數(shù)據(jù)庫的SQL腳本

          【5】udmp:存儲用戶進程所生成的跟蹤文件
          posted @ 2008-05-04 17:41 Paul Lin 閱讀(576) | 評論 (0)編輯 收藏

          1.關于單元測試:

          單元測試中的Test Case在設計時,有兩點要注意的:

          a. 測試的方法最好短小精悍,每個test case只測試一個關注的功能,假如一個方法的處理邏輯里面包含了對幾種可能情況的處理,那么測試案例最好分成幾個來測試,舉例如下
            
             方法: public void convertStringToDate(String string)
           
             在實際應用過程中,傳入?yún)?shù)string的值可能有下面幾種情況:
            
             1). Null
             2). 空格
             3). 非空但格式錯誤
             4). 非空且格式正確,但值錯誤(如:2008-02-31 23:59:59)
             5). 非空且格式、值均正確

             那么如果我們在同一個測試方法中: public void testConvertStringToDate()測試所有的可能情況,會有下面兩個問題:

             1). 代碼量增多
             2). 不利于修改,假如由于業(yè)務方法中某個處理邏輯改變了,此時重新測試時必須測試所有其它的方法
             3). 可能造成測試案例的順序依賴,比如其中某個方法會拋出異常,之后的測試案例可能不會被執(zhí)行到

          如果我們按照上面可能出現(xiàn)的情況來分的話,那么就有五個測試案例,從數(shù)量上看是多了,但是后果就是每個方法都非常短小(不超過6行),簡單明了,一目了然,即便測試案   例錯了,我也能馬上看出來。其次一個測試案例的修改不會影響到其它的測試案例。

          b.測試方法是否拋出異常,可以參考下面的代碼結構:
           
            try{
                調(diào)用被測試代碼 // 此處的代碼必須是明確會拋出異常的,因為這是我們要測試的目的
                fail("Error: Must throw an exception here.");
            } catch(Exception e){
                assertTrue(true);
            }


          2.關于使用DateFormat及其子類進行字符串和日期轉換的注意點:

          使用DateFormat將字符串轉換成Date對象時,必須注意在轉換前,先調(diào)用:setLinient(false);否則的話即使實際的日期數(shù)值有問題,例如2008-04-32 23:59:59,只要格式正確,也能夠被轉換成功,但這在實際的應用中是沒有意義的。

          posted @ 2008-04-28 00:37 Paul Lin 閱讀(216) | 評論 (0)編輯 收藏
               摘要: 最近在使用Oracle9i數(shù)據(jù)庫進行數(shù)據(jù)插入、查詢、導入/出,有時會出現(xiàn)亂碼的情況,具體的情形有以下兩種:

          1.首次插入/顯示亂碼

          2.首次插入/顯示正常、但把數(shù)據(jù)用工具導出為本地文件(例如TXT)文件,再在另一個客戶端中打開該文件并執(zhí)行時
          再次插入的數(shù)據(jù)顯示為亂碼。

          遂在本地創(chuàng)建兩個數(shù)據(jù)庫,一個為AL32UTF8字符集,一個為ZHS16GBK字符集,配合客戶端NLS_LANG的不同設置,測
          試亂碼的情況及進行原因分析。

          希望本文能夠?qū)θ蕴幱贠racle字符集泥潭的同仁一點幫助  閱讀全文
          posted @ 2008-04-23 14:59 Paul Lin 閱讀(7851) | 評論 (0)編輯 收藏
          <project name="autobuildtest" default="test">    
              
          <target name="setProperties">

                  
          <property name="src.dir" value="src"/>
                  
          <property name="classes.dir" value="classes"/>
                 
          </target>
              
              
          <target name="prepareDir" depends="setProperties">
                  
          <delete dir="${classes.dir}"/>
                  
          <mkdir dir="${classes.dir}"/>
              
          </target>
              
              
              
          <target name="compile" depends="prepareDir">
                  
          <javac srcdir="./src" destdir="${classes.dir}"/>     
              
          </target>

              
              
          <target name="test" depends="compile">
                  
          <junit printsummary="yes">
                      
          <test name="onlyfun.caterpillar.test.MathToolTest"/>
                    
          <classpath>
                        <pathelement location="${classes.dir}"/>
                    </classpath>
                  
          </junit>
              
          </target> 
          </project>
           

          上面XML文件高亮處描述了Ant如何與JUnit結合進行自動化測試,name屬性是你要測試的TestCase,classpath元素指明了TestCase的路徑,printsummary說明了要將測試的結果簡單的顯示出來。

          如何吧JUnit測試的詳細信息顯示出來呢?我們可以采用<formatter>元素,如下所示:

          <junit printsummary="yes">

              
          <formatter type="plain" usefile="false"/>

              
          <test name="onlyfun.caterpillar.test.MathToolTest"/>
                
          <classpath>
                  
          <pathelement location="${classes.dir}"/>
                
          </classpath>         
          </junit>

          當usefile屬性設定為true時,會自動幫您將產(chǎn)生的結果儲存在檔案中,預設是TEST-*.txt,其中*是您的測試案例類別名稱。除此之外,我們也可用采用XML的格式來保存測試結果。如下所示:

          <formatter type="xml"/>

          也可以將測試結果所產(chǎn)生的XML文件轉換為HTML文件,使用Ant可以直接幫您完成這個工作,<junitreport>標簽使用 XSLT將XML文件轉換為HTML文件

          <project name="autobuildtest" default="report">

              
          <target name="setProperties">
                  
          <property name="src.dir" value="src"/>
                  
          <property name="classes.dir" value="classes"/>
                  
          <property name="report.dir" value="report"/>    
              
          </target>
              
              
          <target name="prepareDir" depends="setProperties">
                  
          <delete dir="${report.dir}"/>
                  
          <delete dir="${classes.dir}"/>
                  
          <mkdir dir="${report.dir}"/>
                  
          <mkdir dir="${classes.dir}"/>
              
          </target>

              
          <target name="compile" depends="prepareDir">
                  
          <javac srcdir="./src" destdir="${classes.dir}"/>
              
          </target>
              
              
          <target name="test" depends="compile">
                  
          <junit printsummary="yes">
                      
          <formatter type="xml"/>
                      
          <test name="onlyfun.caterpillar.test.MathToolTest"
                              todir="${report.dir}"
          />
                      
          <classpath>
                          
          <pathelement location="${classes.dir}"/>
                      
          </classpath>
                  
          </junit>
              
          </target>

              
          <target name="report" depends="test">
                  
          <junitreport todir="${report.dir}">
                  
          <fileset dir="${report.dir}">
                      
          <include name="TEST-*.xml"/>
                  
          </fileset>
                  
          <report format="frames" todir="${report.dir}/html"/>
              </junitreport>
              
          </target> 
          </project>

          上面的例子,首先定義了一個property,用于指向保存測試結果的目錄,接著在<test>元素中通過<todir>將結果指向該目錄。然后report目標首先在todir屬性指定的目錄下查找名稱包含:TESTd的XML文件,找到之后通過XSL轉換成帶frame的HTML頁面,存放到子目錄html下面

          最終的結果可能如下:


          posted @ 2008-04-21 15:21 Paul Lin 閱讀(666) | 評論 (0)編輯 收藏

          【1】path和location屬性的區(qū)別:
           
          <classpath>
              <pathelement path="${classpath}"/>
               <pathelement location="lib/helper.jar"/>
          </classpath>
           
          原文:The location attribute specifies a single file or directory relative to the project's base directory (or an absolute filename), while the path attribute accepts colon- or semicolon-separated lists of locations. The path attribute is intended to be used with predefined paths - in any other case, multiple
          elements with location attributes should be preferred.
           
          從中我們可以看出path可以用于指向存在多個文件的位置,而location只能指向單個的文件或目錄。另外path可以被設定id,供其它的path或classpath引用。如:<path id="main-classpath">,而classpath則沒有

          【2】綜合示例:
          In addition, DirSets, FileSets, and FileLists can be specified via nested <dirset>, <fileset>, and <filelist> elements, respectively. Note: The order in which the files building up a FileSet are added to the path-like structure is not defined.
           
              <classpath>
                <pathelement path="${classpath}"/方式① :引用特定的變量

                <fileset dir="lib"方式② :指向特定的文件集
                  <include name="**/*.jar"/>
                </fileset>

                <pathelement location="classes"/方式③:指向單個目錄

                <dirset dir="${build.dir}"方式④:指向特定目錄集
                  <include name="apps/**/classes"/>
                  <exclude name="apps/**/*Test*"/>
                </dirset>

                <filelist refid="third-party_jars"/> 方式⑤:引用指定文件列表
              </classpath>
           
          This builds a path that holds the value of ${classpath}, followed by all jar files in the lib directory, the classes directory, all directories named classes under the apps subdirectory of ${build.dir}, except those that have the text Test in their name, and the files specified in the referenced FileList.

          posted @ 2008-04-21 14:28 Paul Lin 閱讀(1929) | 評論 (0)編輯 收藏
               摘要: Visitor模式的一個優(yōu)點體現(xiàn)在對集合元素的訪問中:由于集合中的可訪問元素都實現(xiàn)了Visitable接口,所以在迭代集合的過程中,我們可以將每個元素都看成是接口類型。

          其次由于JAVA語言的多態(tài)性,雖然每個元素都是接口類型(Visitable),但每個元素的實現(xiàn)類不同,所以在調(diào)用accept方法時,虛擬機“知道”應該調(diào)起那個正確的方法(例如:集合中的一個String元素,會調(diào)用StringElement的accept方法)  閱讀全文
          posted @ 2008-04-15 17:38 Paul Lin 閱讀(4481) | 評論 (2)編輯 收藏
          僅列出標題
          共26頁: First 上一頁 18 19 20 21 22 23 24 25 26 下一頁 
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(21)

          隨筆分類

          隨筆檔案

          BlogJava熱點博客

          好友博客

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 祥云县| 祁阳县| 京山县| 大厂| 剑河县| 南川市| 锦州市| 格尔木市| 将乐县| 嵩明县| 铜川市| 健康| 南皮县| 蚌埠市| 东山县| 栖霞市| 东丰县| 辽源市| 普洱| 合江县| 衡阳市| 济宁市| 策勒县| 罗甸县| 尤溪县| 丹凤县| 华容县| 阳朔县| 明水县| 信阳市| 抚松县| 溆浦县| 延安市| 滕州市| 井研县| 江安县| 红河县| 南皮县| 景东| 西藏| 元朗区|