<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    軟件是對質量的不懈追求

    2010年1月9日 #

    linux du 查看文件夾占用空間


    du -sh *

    posted @ 2011-04-15 08:39 BlakeSu 閱讀(280) | 評論 (0)編輯 收藏

    Building Standalone Application with Maven2

    If you are building standalone application in Java, Maven is your friend when packing your application,
    There are two way to let Maven package your application, either as a single jar with all your dependencies jar.


     <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
       <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
       </descriptorRefs>
      </configuration>
     </plugin>



    One advantage if you choose to do this way is if you need to sign your application jar.
    This is needed if you are building a Java Web Start client and you need more access than connecting back to the server.
    To read more about have Maven signing your jar read http://maven.apache.org/plugins/maven-jar-plugin/usage.html.
    But if you choose to go this way, make sure that all license agreement are shipped with your one single jar.

    Another way is to let Maven package your source code only and then referring the dependent jar file from the MANIFEST file.


     <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
       <archive>
        <manifest>
         <addClasspath>true</addClasspath>
         <mainClass>se.msc.adapter.Main</mainClass>
         <classpathPrefix>lib/</classpathPrefix>
        </manifest>
       </archive>
      </configuration>
     </plugin>

    posted @ 2011-02-24 13:03 BlakeSu 閱讀(329) | 評論 (0)編輯 收藏

    eclipse 終于有了列編輯功能

    eclipse 3.5之后終于有了列編輯,快捷鍵是alt+shift+a,再次按此快捷鍵返回常規編輯狀態。


    posted @ 2010-10-15 11:33 BlakeSu 閱讀(1484) | 評論 (0)編輯 收藏

    LineNumberReader 指定文件編碼


    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.LineNumberReader;


    public class Main {
        
        
    public static void main(String[] args) throws IOException {

            InputStreamReader isr 
    = new InputStreamReader(new FileInputStream("15370720.pdf4"), "utf-16");
            LineNumberReader lnr
    =new LineNumberReader(isr);
            String line 
    = null;
            
    while((line=lnr.readLine())!=null){  
               System.out.println(lnr.getLineNumber()
    +"\t"+line);
            }
       }
    }

    posted @ 2010-08-05 09:13 BlakeSu 閱讀(1049) | 評論 (0)編輯 收藏

    Class.getResourceAsStream 和 ClassLoader.getResourceAsStream

    兩個方法的區別是資源的定義不同, 一個主要用于相對與一個object取資源,而另一個用于取相對于classpath的
    資源,用的是絕對路徑。

    在使用Class.getResourceAsStream 時, 資源路徑有兩種方式, 一種以 / 開頭,則這樣的路徑是指定絕對
    路徑, 如果不以 / 開頭, 則路徑是相對與這個class所在的包的。

    在使用ClassLoader.getResourceAsStream時, 路徑直接使用相對于classpath的絕對路徑。

    舉例,下面的三個語句,實際結果是一樣的:
       com.explorers.Test.class.getResourceAsStream("abc.jpg")
    = com.explorers.Test.class.getResourceAsStream("/com/explorers/abc.jpg")
    = ClassLoader.getResourceAsStream("com/explorers/abc.jpg")

    posted @ 2010-07-28 16:31 BlakeSu 閱讀(295) | 評論 (0)編輯 收藏

    Standalone Java CAS Client

    There's a variety of clients for CAS. The Java-based clients (JA-SIG, Yale, see JA-SIG website) typically handle the browser-based client interaction with CAS very well through ServletFilter implementations.

    Now what about programmatic authentication, i.e. achieving authentication through non-browser based applications? There exists a CAS .NET client but I did not manage to find the appropriate Java implementation. So here goes - it is based on the Apache HttpClient.

    In case I missed any existing implementation achieving the same purpose, let's look at the bright side: at least now I understand the CAS protocol :-)

    My CAS client works within any application. It uses the HttpClient and behaves like a browser client as CAS requires cookie support.

    Here's the code:
    import org.apache.commons.httpclient.Header;
    import org.apache.commons.httpclient.HttpClient;
    import org.apache.commons.httpclient.HttpMethod;
    import org.apache.commons.httpclient.HttpStatus;
    import org.apache.commons.httpclient.methods.GetMethod;
    import org.apache.commons.httpclient.methods.PostMethod;
    import org.apache.log4j.Logger;

    /**
    * The CasClient allows users to programmatically login
    * to CAS protected services based on the CAS 2 protocol.
    * This client behaves like a browser-client in terms of
    * cookie handling.<br>
    *
    @author Mathias Richter
    */
    public class CasClient
    {
      
       
    public static Logger LOG = Logger.getLogger( CasClient.class  );

       
    public static final String LOGIN_URL_PART = "login";
       
    public static final String SERVICE_VALIDATE_URL_PART = "serviceValidate";
       
    public static final String TICKET_BEGIN = "ticket=";
       
    private static final String LT_BEGIN = "name="lt" value="";
       public static final String CAS_USER_BEGIN = "<cas:user>";
       
    public static final String CAS_USER_END = "</cas:user>";
      
       
    private HttpClient fClient;
       
    private String fCasUrl;
      
       
    /**
        * Construct a new CasClient.
        *
        * 
    @param casUrl The base URL of the CAS service to be used.
        
    */
       
    public CasClient( String casBaseUrl )
       {
           
    thisnew HttpClient(), casBaseUrl );
       }
      
       
    /**
        * Construct a new CasClient which uses the specified HttpClient
        * for its HTTP calls.
        *
        * 
    @param client
        * 
    @param casBaseUrl
        
    */
       
    public CasClient( HttpClient client, String casBaseUrl )
       {
           fClient 
    = client;
           fCasUrl 
    = casBaseUrl;
       }
      
       
    /**
        * Authenticate the specified username with the specified password.
        * This will not yield any ticket, as no service is authenticated
        * against. This wil just set the CAS cookie in this client upon
        * successful authentication.
        *
        * 
    @param username
        * 
    @param password
        
    */
       
    public void authenticate( String username, String password )
       {
           authenticate( 
    null, username, password );
       }
      
       
    /**
        * Validate the specified service ticket against the specified service.
        * If the ticket is valid, this will yield the clear text user name
        * of the autenticated user.<br>
        * Note that each service ticket issued by CAS can be used exactly once
        * to validate.
        *
        * 
    @param serviceUrl
        * 
    @param serviceTicket
        *
        * 
    @return Clear text username of the authenticated user.
        
    */
       
    public String validate( String serviceUrl, String serviceTicket )
       {
           String result 
    = null;
           PostMethod method 
    = new PostMethod( fCasUrl + SERVICE_VALIDATE_URL_PART );
           method.setParameter( 
    "service", serviceUrl );
           method.setParameter( 
    "ticket", serviceTicket );
           
    try
           {
               
    int statusCode = fClient.executeMethod(method);
               
    if (statusCode != HttpStatus.SC_OK)
               {
                   LOG.error( 
    "Could not validate: " + method.getStatusLine() );
                   method.releaseConnection();
               } 
    else
               {   
                   result 
    = extractUser( new String( method.getResponseBody() ) );
               }
           } 
    catch ( Exception x )
           {
               LOG.error( 
    "Could not validate: " + x.toString () );
               x.printStackTrace();
           }
           method.releaseConnection();
           
    return result;
       }
      
       
    /**
        * Authenticate the specified user with the specified password against the
        * specified service.
        *
        * 
    @param serviceUrl May be null. If a url is specified, the authentication will happen against this service, yielding a service ticket which can be validated.
        * 
    @param username
        * 
    @param password
        * 
    @return A valid service ticket, if and only if the specified service URL is not null.
        
    */
       
    public String authenticate( String serviceUrl, String username, String password )
       {
           String lt 
    = getLt( serviceUrl );
           
    if ( lt == null )
           {
               LOG.error( 
    "Cannot retrieve LT from CAS. Aborting authentication for '" + username + "'" );
               
    return null;
           }
           String result 
    = null;
           PostMethod method 
    = new PostMethod( fCasUrl + LOGIN_URL_PART );
           
    if ( serviceUrl != null ) // optional
               method.setParameter( "service", serviceUrl );
           method.setParameter( 
    "_eventId""submit" );
           method.setParameter(
    "username", username );
           method.setParameter(
    "password", password );
           method.setParameter(
    "lt", lt );
           method.setParameter( 
    "gateway""true" );
           
    try
           {
               fClient.executeMethod(method);
               
    if ( serviceUrl == null )
               {
                   
    if ( extractLt( new String( method.getResponseBody() ) ) != null ) // if CAS does not return a login page with an LT authentication was successful
                   {
                       LOG.error( 
    "Authentication for '" +  username + "' unsuccessful" );
                       
    if ( LOG.isDebugEnabled() )
                           LOG.debug( 
    "Authentication for '" + username + "' unsuccessful." );
                   } 
    else
                   {
                       
    if ( LOG.isDebugEnabled() )
                           LOG.debug( 
    "Authentication for '" + username + "' unsuccessful." );
                   }
               } 
    else
               {
                   Header h 
    = method.getResponseHeader( "Location" );
                   
    if ( h != null )
                       result 
    = extractServiceTicket( h.getValue() );
                   
    if ( result == null )
                       LOG.error( 
    "Authentication for '" + username + "' unsuccessful." );
               }
           } 
    catch ( Exception x )
           {
               LOG.error( 
    "Could not authenticate'" + username + "':" + x.toString () );
           }
           method.releaseConnection();
           
    return result;
       }
      
       
    /**
        * Helper method to extract the user name from a "service validate" call to CAS.
        *
        * 
    @param data Response data.
        * 
    @return The clear text username, if it could be extracted, null otherwise.
        
    */
       
    protected String extractUser( String data )
       {
           String user 
    = null;
           
    int start = data.indexOf( CAS_USER_BEGIN  );
           
    if ( start >= 0 )
           {
               start 
    += CAS_USER_BEGIN.length();
               
    int end = data.indexOf( CAS_USER_END );
               
    if ( end > start )
                   user 
    = data.substring( start, end );
               
    else
                   LOG.warn( 
    "Could not extract username from CAS validation response. Raw data is: '" + data + "'" );
           } 
    else
           {
               LOG.warn( 
    "Could not extract username from CAS validation response. Raw data is: '" + data + "'" );
           }
           
    return user;
       }
      
       
    /**
        * Helper method to extract the service ticket from a login call to CAS.
        *
        * 
    @param data Response data.
        * 
    @return The service ticket, if it could be extracted, null otherwise.
        
    */
       
    protected String extractServiceTicket( String data )
       {
           String serviceTicket 
    = null;
           
    int start = data.indexOf( TICKET_BEGIN  );
           
    if ( start > 0 )
           {
               start 
    += TICKET_BEGIN.length();
               serviceTicket 
    = data.substring( start );
           }
           
    return serviceTicket;
       }
      
       
    /**
        * Helper method to extract the LT from a login form from CAS.
        *
        * 
    @param data Response data.
        * 
    @return The LT, if it could be extracted, null otherwise.
        
    */
       
    protected String extractLt( String data )
       {
           String token 
    = null;
           
    int start = data.indexOf( LT_BEGIN  );
           
    if ( start < 0 )
           {
               LOG.error( 
    "Could not obtain LT token from CAS: LT Token not found in response." );
           } 
    else
           {
               start 
    += LT_BEGIN.length();
               
    int end = data.indexOf( """, start );
               token = data.substring( start, end );
           }       
           
    return token;
       }
      
       
    /**
        * This method requests the original login form from CAS.
        * This form contains an LT, an initial token that must be
        * presented to CAS upon sending it an authentication request
        * with credentials.<br>
        * If a service URL is provided (which is optional), this method
        * will post the URL such that CAS authenticates against the
        * specified service when a subsequent authentication request is
        * sent.
        *
        * 
    @param serviceUrl
        * 
    @return The LT token if it could be extracted from the CAS response.
        
    */
       
    protected String getLt( String serviceUrl )
       {
           String lt 
    = null;
           HttpMethod method 
    = null;
           
    if ( serviceUrl == null )
               method 
    = new GetMethod( fCasUrl + LOGIN_URL_PART );
           
    else
           {
               method 
    = new PostMethod( fCasUrl + LOGIN_URL_PART );
               ( ( PostMethod ) method ).setParameter( 
    "service", serviceUrl );
           }
           
    try
           {
               
    int statusCode = fClient.executeMethod(method);
               
    if (statusCode != HttpStatus.SC_OK)
               {
                   LOG.error( 
    "Could not obtain LT token from CAS: " + method.getStatusLine() );
                   method.releaseConnection();
               } 
    else
               {
                   Object o 
    = method.getResponseHeaders() ;
                   
    return extractLt( new String( method.getResponseBody() ) );
               }
           } 
    catch ( Exception x )
           {
               LOG.error( 
    "Could not obtain LT token from CAS: " + x.toString () );
           }
           method.releaseConnection();
           
    return lt;
       }
      
    }

    posted @ 2010-07-15 17:59 BlakeSu 閱讀(416) | 評論 (0)編輯 收藏

    java取文件換行符

    System.getProperty("line.separator")

    posted @ 2010-06-30 15:45 BlakeSu 閱讀(311) | 評論 (0)編輯 收藏

    禁止瀏覽器緩存

    html
      <meta http-equiv="pragma" content="no-cache">
      
    <meta http-equiv="cache-control" content="no-cache">
      
    <meta http-equiv="expires" content="0">


    servlet
              response.setHeader("pragma","no-cache");
              response.setHeader(
    "cache-control","no-cache");
              response.setDateHeader(
    "expires"0);


    posted @ 2010-06-25 09:06 BlakeSu 閱讀(253) | 評論 (0)編輯 收藏

    frame 中跨域訪問cookie(java)

    response.addHeader("P3P","CP=CAO PSA OUR");

    posted @ 2010-06-25 09:04 BlakeSu 閱讀(414) | 評論 (0)編輯 收藏

    vim的復制粘貼小結

    原文地址 http://lsong17.spaces.live.com/blog/cns!556C21919D77FB59!603.trak


    用vim這么久 了,始終也不知道怎么在vim中使用系統粘貼板,通常要在網上復制一段代碼都是先gedit打開文件,中鍵粘貼后關閉,然后再用vim打開編輯,真的不 爽;上次論壇上有人問到了怎么在vim中使用系統粘貼板,印象里回復很多,有好幾頁的回復卻沒有解決問題,今天實在受不了了又在網上找辦法,竟意外地找到 了,貼出來分享一下。

    如果只是想使用系統粘貼板的話直接在輸入模式按Shift+Inset就可以了,下面講一下vim的粘貼板的基礎知識,有興趣的可以看看, 應該會有所收獲的。
    vim幫助文檔里與粘貼板有關的內容如下:

    1. vim有12個粘貼板,分別是0、1、2、...、9、a、“、+;用:reg命令可以查看各個粘貼板里的內容。在vim中簡單用y只是復制到 “(雙引號)粘貼板里,同樣用p粘貼的也是這個粘貼板里的內容;

    2. 要將vim的內容復制到某個粘貼板,需要退出編輯模式,進入正常模式后,選擇要復制的內容,然后按"Ny完成復制,其中N為粘 貼板號(注意是按一下雙引號然后按粘貼板號最后按y),例如要把內容復制到粘貼板a,選中內容后按"ay就可以了,有兩點需要說明一下:
      • “號粘貼板(臨時粘貼板)比較特殊,直接按y就復制到這個粘貼板中了,直接按p就粘貼這個粘貼板中的內容;
      • +號粘貼板是系統粘貼板,用"+y將內容復制到該粘貼板后可以使用Ctrl+V將其粘貼到其他文檔(如firefox、gedit) 中,同理,要把在其他地方用Ctrl+C或右鍵復制的內容復制到vim中,需要在正常模式下按"+p;

    3. 要將vim某個粘貼板里的內容粘貼進來,需要退出編輯模式,在正常模式按"Np,其中N為粘貼板號,如上所述,可以按"5p將 5號粘貼板里的內容粘貼進來,也可以按"+p將系統全局粘貼板里的內容粘貼進來。

    注意:在我這里,只有vim.gtk或vim.gnome才能使用系統全局粘貼板,默認的 vim.basic看不到+號寄存器。

    posted @ 2010-06-18 14:21 BlakeSu 閱讀(264) | 評論 (0)編輯 收藏

    Linux下mail使用技巧

    登錄LINUX系統后,經常會看到"you have mail",卻苦于不知道如何查看,相信菜鳥們都遇到過,偶在網上用“linux mail"找了很久,但大都是介紹mail服務器的,黃天總算沒負有心人,在洪恩在找到一篇介紹基礎的文章,不敢獨享。
     
    系統提供了用戶 之間通信的郵件系統,當用戶打開終端注冊登錄時發現系統給出如下信息:
        you have mail.

        這時用戶可通過鍵入mail命令讀取信件:

        $ mail

        mail程序將逐個顯示用戶的信件,并依照時間順序,顯示最新的信件。每顯示一段信件,mail都詢問用戶是否要對該信件作些處理。若用戶回答d,則表示 刪除信件;若僅按回車鍵,表示對信件不作任何改動(信件仍舊保存,下次還可讀這一信件);若回答p,則要求重復顯示信件;s filename表示要把信件存入所命名的文件;若回答q,表示要從mail退出。

        我們在本章的第一個例子中演示了如何寫一封信,作為練習,你可送信件給自己,然后鍵入mail讀取自己發的信件,看看會有什么效果。(發信給自己是一種設 置備忘錄的方法)。

        $mail frank 給自己寫信

        subject: test

        This is a mail test

        CRL-d

        EOT

        $

        $mail 查看信件

        “/var/spool/mail/frank:”1 message 1 new

        >Nfrank@xteam.xteamlinux.comThu Mar 25 11:00 13/403 “test”

        &

        Message 1:

        From frank Thu Mar 25 11:00:25 1999/3/25

        Received: (fromfrank@localhost)

        by xteam.xteamlinux.com(8.8.4/8.8.4)

        id LAA05170 for frank;Thu 25 Mar 1999 11:00:25 GMT

        Date: Thu,25 Mar 1999 11:00:25 GMT

        From:RHS Linux User <frank@xteam.xteamlinux.com>

        Message-Id:<199903251142.LAA05170@xteam.xteamlinux.com>

        To:frank@xteam.xteamlinux.com

        Subject:test

        Status:R

        This is a mail test

        &

        mail命令還有很多其它用法,例如發送事先準備好的信件,或一次送信給若干人。還可以用其它方法送信件。

    posted @ 2010-06-18 11:05 BlakeSu 閱讀(190) | 評論 (0)編輯 收藏

    Mysql中limit的用法詳解

        Mysql中limit的用法:在我們使用查詢語句的時候,經常要返回前幾條或者中間某幾行數據,這個時候怎么辦呢?
      不用擔心,mysql已經為我們提供了這樣一個功能。

      SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset

    LIMIT 子句可以被用于強制 SELECT 語句返回指定的記錄數。LIMIT 接受一個或兩個數字參數。參數必須是一個整數常量。
      如果給定兩個參數,第一個參數指定第一個返回記錄行的偏移量,第二個參數指定返回記錄行的最大數目。初始記錄行的偏移量是 0(而不是 1):
      為了與 PostgreSQL 兼容,MySQL 也支持句法: LIMIT # OFFSET #。

    mysql> SELECT * FROM table LIMIT 5,10; // 檢索記錄行 6-15

    //為了檢索從某一個偏移量到記錄集的結束所有的記錄行,可以指定第二個參數為 -1:

    mysql> SELECT * FROM table LIMIT 95,-1; // 檢索記錄行 96-last.

    //如果只給定一個參數,它表示返回最大的記錄行數目:

    mysql> SELECT * FROM table LIMIT 5; //檢索前 5 個記錄行

    //換句話說,LIMIT n 等價于 LIMIT 0,n。

    注意limit 10和limit 9,1的不同:

    例如:

    1.Select * From cyclopedia Where ID>=(
        Select Max(ID) From (
          Select ID From cyclopedia Order By ID limit 90001
        ) As tmp
      ) limit 100;

    2.Select * From cyclopedia Where ID>=(
        Select Max(ID) From (
          Select ID From cyclopedia Order By ID limit 90000,1
        ) As tmp
      ) limit 100;

     

        第1句是先取了前90001條記錄,取其中最大一個ID值作為起始標識,然后利用它可以快速定位下100條記錄

    第2句擇是僅僅取90000條記錄后1條,然后取ID值作起始標識定位下100條記錄

    第1句執行結果.100 rows in set (0.23) sec

    第2句執行結果.100 rows in set (0.19) sec

    其實第2句完全可以簡化成:
        Select * From cyclopedia Where ID>=(
       Select ID From cyclopedia limit 90000,1
    )limit 100;

    直接利用第90000條記錄的ID,不用經過Max運算,這樣做理論上效率因該高一些,但在實際使用中幾乎看不到效果,
       因為本身定位ID返回的就是1條記錄,Max幾乎不用運作就能得到結果,但這樣寫更清淅明朗,省去了畫蛇那一足.


    Select Top 100 * From cyclopedia Where ID>=(
    Select Top 90001 Max(ID) From (
    Select ID From cyclopedia Order By ID
    ) As tmp
    )

    但不管是實現方式是存貯過程還是直接代碼中,瓶頸始終在于MS-SQL的TOP總是要返回前N個記錄,這種情況在數據量不大時感受不深,
       但如果成百上千萬,效率肯定會低下的.相比之下MySQL的limit就有優勢的多,執行:


    Select ID From cyclopedia limit 90000
    Select ID From cyclopedia limit 90000,1

    的結果分別是:


    90000 rows in set (0.36) sec
    1 row in set (0.06) sec

    而MS-SQL只能用Select Top 90000 ID From cyclopedia 執行時間是390ms,執行同樣的操作時間也不及MySQL的360ms.

    limit的offset(偏移量)用于記錄較多的時候,記錄較少時,偏移offset較小,直接使用limit較優。offset越大,后者越優。
     

    1、offset比較小的時候。

    select * from yanxue8_visit limit 10,10

    多次運行,時間保持在0.0004-0.0005之間


    Select * From yanxue8_visit Where vid >=(
      Select vid From yanxue8_visit Order By vid limit 10,1
    ) limit 10

    多次運行,時間保持在0.0005-0.0006之間,主要是0.0006

    結論:偏移offset較小的時候,直接使用limit較優。這個顯示是子查詢的原因。

    2、offset大的時候。

    select * from yanxue8_visit limit 10000,10

    多次運行,時間保持在0.0187左右

    Select * From yanxue8_visit Where vid >=(
      Select vid From yanxue8_visit Order By vid limit 10000,1
    ) limit 10

    多次運行,時間保持在0.0061左右,只有前者的1/3。可以預先offset越大,后者越優。

    mysql> SELECT * FROM table LIMIT 95,-1; // 檢索記錄行 96-last.

    //如果只給定一個參數,它表示返回最大的記錄行數目.

    posted @ 2010-06-02 14:43 BlakeSu 閱讀(451) | 評論 (0)編輯 收藏

    枚舉類型enum示例




    public enum OrderStatus {
        A(
    1), B(2), C(3), D(4), F(5), INCOMPLETE(6);
        
        
    private final int value;
        
    /**
         * Constructor.
         
    */
        
    private OrderStatus(int value) {
            
    this.value = value;
        }
        
        
    /**
         * Get the value.
         * 
    @return the value
         
    */
        
    public int getValue() {
            
    return value;
        }

    }


    posted @ 2010-06-02 13:33 BlakeSu 閱讀(147) | 評論 (0)編輯 收藏

    JS try.....catch的使用

    <script language="javascript">
    try
    {
    throw new Error(10,"asdasdasd")
    }
    catch (e)
    {
    alert(e.message);
    alert(e.description)
    alert(e.number)
    alert(e.name)
    throw new Error(10,"asdasdasd")
    }

    </script>  

    在JavaScript可以使用try...catch來進行異常處理。例如:  

     

    try {
    foo.bar();
    } catch (e) {
    alert(e.name + ": " + e.message);
    }

    目前我們可能得到的系統異常主要包含以下6種:

    • EvalError: raised when an error occurs executing code in eval()  
    • RangeError: raised when a numeric variable or parameter is outside of its valid range  
    • ReferenceError: raised when de-referencing an invalid reference  
    • SyntaxError: raised when a syntax error occurs while parsing code in eval()  
    • TypeError: raised when a variable or parameter is not a valid type  
    • URIError: raised when encodeURI() or decodeURI() are passed invalid parameters  

    上面的六種異常對象都繼承自Error對象。他們都支持以下兩種構造方法:

     

    new Error();
    new Error("異常信息");

    手工拋出異常的方法如下:

     

    try {
    throw new Error("Whoops!");
    } catch (e) {
    alert(e.name + ": " + e.message);
    }

    如要判斷異常信息的類型,可在catch中進行判斷:

     

    try {
    foo.bar();
    } catch (e) {
    if (e instanceof EvalError) {
       alert(e.name + ":" + e.message);
    }
    else if (e instanceof RangeError) {
       alert(e.name + ": " + e.message);
    }
    // etc
    }

    Error具有下面一些主要屬性:

    • description: 錯誤描述 (僅IE可用).  
    • fileName: 出錯的文件名 (僅Mozilla可用).  
    • lineNumber: 出錯的行數 (僅Mozilla可用).  
    • message: 錯誤信息 (在IE下同description)  
    • name: 錯誤類型.  
    • number: 錯誤代碼 (僅IE可用).  
    • stack: 像Java中的Stack Trace一樣的錯誤堆棧信息 (僅Mozilla可用).  

    因此為了更好的了解錯誤信息我們可以將catch部分改為如下形式:  

     

    try {
    foo.bar();
    } catch (e) {
    if (browserType != BROWSER_IE) {                            
       alert("name: " + e.name +
        "message: " + e.message +
        "lineNumber: " + e.lineNumber +
        "fileName: " + e.fileName +
        "stack: " + e.stack);        
    }
    else {                    
       alert("name: " + e.name +     
        "errorNumber: " + (e.number & 0xFFFF ) +
        "message: " + e.message");        
    }
    }

    JavaScript中的throw命令事實上可以拋出任何對象,并且我們可以在catch接受到此對象。例 如:

     

    try {
    throw new Date(); // 拋出當前時間對象
    } catch (e) {
    alert(e.toLocaleString()); // 使用本地格式顯示當前時間
    }

    posted @ 2010-06-02 10:38 BlakeSu 閱讀(330) | 評論 (0)編輯 收藏

    深拷貝

    import java.io.*;

    public class ObjectCloner
    {
       
    // so that nobody can accidentally create an ObjectCloner object
       private ObjectCloner(){}
       
    // returns a deep copy of an object
       static public Object deepCopy(Object oldObj) throws Exception
       {
          ObjectOutputStream oos 
    = null;
          ObjectInputStream ois 
    = null;
          
    try
          {
             ByteArrayOutputStream bos 
    = new ByteArrayOutputStream(); 
             oos 
    = new ObjectOutputStream(bos); 
             
    // serialize and pass the object
             oos.writeObject(oldObj);   
             oos.flush();               
             ByteArrayInputStream bin 
    = new ByteArrayInputStream(bos.toByteArray()); 
             ois 
    = new ObjectInputStream(bin);
             
    // return the new object
             return ois.readObject();
          }
          
    catch(Exception e)
          {
             System.out.println(
    "Exception in ObjectCloner = " + e);
             
    throw(e);
          }
          
    finally
          {
             oos.close();
             ois.close();
          }
       }
       
    }

    posted @ 2010-05-25 09:30 BlakeSu 閱讀(176) | 評論 (0)編輯 收藏

    mysql convert int to char/varchar

    select cast(1 as char)

    char 不能換成varchar,否則會報錯。

    posted @ 2010-05-12 17:12 BlakeSu 閱讀(2894) | 評論 (0)編輯 收藏

    How to check Linux distribution and version?

    If u are on an unknown server and keen to know it’s linux distribution info, you can check the linux distribution info by just a single command (eg. version, codename, etc). Just tested this command in UBuntu and CentOS, both return as what i expected. :)

    To check linux distribution and version, follow the steps below:-

    • Start your terminal and enter the command below to show your the linux distribution info:-
      $ cat /etc/*-release
    • Here’s my result in one of my my Ubuntu box:-
      $ cat /etc/*-release
      DISTRIB_ID=Ubuntu
      DISTRIB_RELEASE=9.10
      DISTRIB_CODENAME=karmic
      DISTRIB_DESCRIPTION="Ubuntu 9.10"

      Cool right!

    posted @ 2010-05-08 13:29 BlakeSu 閱讀(684) | 評論 (0)編輯 收藏

    Eclipse集成windows資源管理器簡單方法

    Run-->External Tools-->External tools configurations
    new 一個 program
    location 里面填 :C:\WINDOWS\explorer.exe
    Arguments 里面填: ${container_loc}
    點擊 Run

    posted @ 2010-05-08 08:40 BlakeSu 閱讀(262) | 評論 (0)編輯 收藏

    commons lang 比較有用的類

    ArrayUtils                 //簡化數組的操作
    LocaleUtils
    SerializationUtils
    StringEscapeUtils
    StringUtils
    SystemUtils
    Validate                   //輸入參數驗證
    NestableException
    NestableRuntimeException
    StopWatch          //秒表類

    posted @ 2010-04-26 10:16 BlakeSu 閱讀(207) | 評論 (0)編輯 收藏

    xmind 當真不錯

    xmind是繪制思維導圖的工具。
    使用之后,發現繪制組織結構圖和wbs都很方便。
    軟件基于eclipse框架開發,反應速度和操作性也都很不錯。
    更重要的,圖形的效果也是專業級的 :)

    posted @ 2010-04-23 09:51 BlakeSu 閱讀(249) | 評論 (0)編輯 收藏

    Java 中serialVersionUID的解釋

    serialVersionUID作用:
           序列化時為了保持版本的兼容性,即在版本升級時反序列化仍保持對象的唯一性。
    有兩種生成方式:
           一個是默認的1L,比如:private static final long serialVersionUID = 1L;
           一個是根據類名、接口名、成員方法及屬性等來生成一個64位的哈希字段,比如:
           private static final   long     serialVersionUID = xxxxL;

    當你一個類實現了Serializable接口,如果沒有定義serialVersionUID,Eclipse會提供這個
         提示功能告訴你去定義 。在Eclipse中點擊類中warning的圖標一下,Eclipse就會
         自動給定兩種生成的方式。如果不想定義它,在Eclipse的設置中也
          可以把它關掉的,設置如下:
            Window ==> Preferences ==> Java ==> Compiler ==> Error/Warnings ==>
            Potential programming problems
            將Serializable class without serialVersionUID的warning改成ignore即可。

    如果你沒有考慮到兼容性問題時,就把它關掉,不過有這個功能是好的,只要任何類別實現了Serializable這個接口的話,如果沒有加入 serialVersionUID,Eclipse都會給你warning提示,這個serialVersionUID為了讓該類別 Serializable向后兼容。

    如果你的類Serialized存到硬盤上面后,可是后來你卻更改了類別的field(增加或減少或改名),當你Deserialize時,就會出現 Exception的,這樣就會造成不兼容性的問題。

    但當serialVersionUID相同時,它就會將不一樣的field以type的預設值Deserialize,可避開不兼容性問題。

    posted @ 2010-04-08 10:37 BlakeSu 閱讀(158) | 評論 (0)編輯 收藏

    spring 相關

    ApplicationContext wac = WebApplicationContextUtils          .getRequiredWebApplicationContext(config.getServletContext());

    posted @ 2010-04-06 13:01 BlakeSu 閱讀(151) | 評論 (0)編輯 收藏

    wesphere6.1修改默認端口

    環境->虛擬主機->default_host->其它屬性(主機別名)->修改端口
    服務器->應用程序服務器->server1->端口->WC_defaulthost->修改端口

    posted @ 2010-04-02 10:36 BlakeSu 閱讀(225) | 評論 (0)編輯 收藏

    jquery validate自定義驗證方法


     /* 追加自定義驗證方法 */   
     
    // 身份證號碼驗證   
     jQuery.validator.addMethod("idcardno"function(value, element) {
       
    return this.optional(element) || isIdCardNo(value);   
     }, 
    "請正確輸入身份證號碼");
     
      
    //字母數字
     jQuery.validator.addMethod("alnum"function(value, element) {
       
    return this.optional(element) || /^[a-zA-Z0-9]+$/.test(value);
     }, 
    "只能包括英文字母和數字");
     
      
    // 手機號碼驗證   
     jQuery.validator.addMethod("cellphone"function(value, element) {
       
    var length = value.length;
       
    return this.optional(element) || (length == 11 && /^(1\d{10})$/.test(value));
     }, 
    "請正確填寫手機號碼"); 
     
      
    // 電話號碼驗證   
     jQuery.validator.addMethod("telephone"function(value, element) {
       
    var tel = /^(\d{3,4}-?)?\d{7,9}$/g;
       
    return this.optional(element) || (tel.test(value));
     }, 
    "請正確填寫電話號碼");
     
     
    // 郵政編碼驗證
     jQuery.validator.addMethod("zipcode"function(value, element) {
       
    var tel = /^[0-9]{6}$/;
       
    return this.optional(element) || (tel.test(value));
     }, 
    "請正確填寫郵政編碼");
     
      
    // 漢字
     jQuery.validator.addMethod("chcharacter"function(value, element) {
       
    var tel = /^[\u4e00-\u9fa5]+$/;
       
    return this.optional(element) || (tel.test(value));
     }, 
    "請輸入漢字");
     
     
    /**
     * 身份證號碼驗證
     *
     
    */
    function isIdCardNo(num) {

     
    var factorArr = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1);
     
    var parityBit=new Array("1","0","X","9","8","7","6","5","4","3","2");
     
    var varArray = new Array();
     
    var intValue;
     
    var lngProduct = 0;
     
    var intCheckDigit;
     
    var intStrLen = num.length;
     
    var idNumber = num;
       
    // initialize
         if ((intStrLen != 15&& (intStrLen != 18)) {
             
    return false;
         }
         
    // check and set value
         for(i=0;i<intStrLen;i++) {
             varArray[i] 
    = idNumber.charAt(i);
             
    if ((varArray[i] < '0|| varArray[i] > '9') && (i != 17)) {
                 
    return false;
             } 
    else if (i < 17) {
                 varArray[i] 
    = varArray[i] * factorArr[i];
             }
         }
         
         
    if (intStrLen == 18) {
             
    //check date
             var date8 = idNumber.substring(6,14);
             
    if (isDate8(date8) == false) {
                
    return false;
             }
             
    // calculate the sum of the products
             for(i=0;i<17;i++) {
                 lngProduct 
    = lngProduct + varArray[i];
             }
             
    // calculate the check digit
             intCheckDigit = parityBit[lngProduct % 11];
             
    // check last digit
             if (varArray[17!= intCheckDigit) {
                 
    return false;
             }
         }
         
    else{        //length is 15
             //check date
             var date6 = idNumber.substring(6,12);
             
    if (isDate6(date6) == false) {

                 
    return false;
             }
         }
         
    return true;
         
     }
    /**
     * 判斷是否為“YYYYMM”式的時期
     *
     
    */
    function isDate6(sDate) {
       
    if(!/^[0-9]{6}$/.test(sDate)) {
          
    return false;
       }
       
    var year, month, day;
       year 
    = sDate.substring(04);
       month 
    = sDate.substring(46);
       
    if (year < 1700 || year > 2500return false
       
    if (month < 1 || month > 12return false
       
    return true
    }
    /**
     * 判斷是否為“YYYYMMDD”式的時期
     *
     
    */
    function isDate8(sDate) {
       
    if(!/^[0-9]{8}$/.test(sDate)) {
          
    return false;
       }
       
    var year, month, day;
       year 
    = sDate.substring(04);
       month 
    = sDate.substring(46);
       day 
    = sDate.substring(68);
       
    var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]
       
    if (year < 1700 || year > 2500return false
       
    if (((year % 4 == 0&& (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
       
    if (month < 1 || month > 12return false
       
    if (day < 1 || day > iaMonthDays[month - 1]) return false
       
    return true
    }




    posted @ 2010-03-30 11:30 BlakeSu 閱讀(3020) | 評論 (2)編輯 收藏

    Mozilla Thunderbird的一些設置

    為了在windows和linux平臺公用相同的郵件客戶端和郵件內容,主要是有時候切換操作系統又要看以前的郵件。最后找到了 thunderbird(下面簡稱TB)客戶端。這個客戶端就是有點慢,倒是能滿足我的要求。但是它的默認設置有時候有點不符合我們的使用習慣,我對它的 設置作了下面的一些修改:

        1:轉發郵件
           默認的設置轉發把郵件的內容作為附件轉發。這樣有兩個不好的地方:第一,如果郵件有附件,這個附件不能轉發;第二,接收方必須要用TB客戶端了,否則打不 開。
           修改:編輯 -> 首選項 -> 編寫 -> 常規:轉發消息改成內聯
       
        2:其它郵件客戶端接收TB發的中文附件是亂碼
           這個是標準問題,TB使用的是新的標準,但是別的客戶端使用的是舊的標準(具體那個標準忘了,google一下就可以了)。這樣就會出現亂碼了。
           修改:編輯 -> 首選項 -> 高級 -> 配置編輯器:mail.strictly_mime.parm_folding 改成0或者1

        3:自動打開附件
           TB默認的是在打開郵件的時候同時自動打開郵件的附件。這樣的話,如果附件大就很頭痛。
           修改:編輯 -> 首選項 -> 高級 -> 配置編輯器:
              mail.inline_attachments   改成faulse
              mail.content_disposition.type   改成1

        4:回復郵件時回復的郵件內容在下面
           TB默認的回復郵件的回復內容是在下面的,這樣如果郵件來回幾次,回復比較多,看起來很不方便。
           修改:編輯 -> 首選項 -> 高級 -> 配置編輯器:Mail.identify.default.reply_on_top值由0改為1
      
        還有一個問題沒有解決,就是有時候在TB中打開一個文件夾,它會重新建索引還是什么的,這時候打開一個文件夾比較慢。看網上有說把這個文件夾重命名,再創 建一個同名的文件夾,最后把老的文件夾的內容拷貝到新的里面就好了,這個沒有試過。不過這個也不是特別大的問題,就沒有繼續搞了,什么時候有空再看看,到 時候再貼上來。

    posted @ 2010-03-19 16:39 BlakeSu 閱讀(701) | 評論 (0)編輯 收藏

    tar命令詳解

    格式:  tar  選項  文件目錄列表
    功能:  對文件目錄進行打包備份
    選項:
    -c  建立新的歸檔文件
    -r  向歸檔文件末尾追加文件
    -x  從歸檔文件中解出文件
    -O  將文件解開到標準輸出
    -v  處理過程中輸出相關信息
    -f  對普通文件操作
    -z  調用gzip來壓縮歸檔文件,與-x聯用時調用gzip完成解壓縮
    -Z  調用compress來壓縮歸檔文件,與-x聯用時調用compress完成解壓縮  
    例如:
    1.將當前目錄下所有.txt文件打包并壓縮歸檔到文件this.tar.gz,我們可以使用
    tar czvf this.tar.gz ./*.txt
    2.將當前目錄下的this.tar.gz中的文件解壓到當前目錄我們可以使用
    tar xzvf this.tar.gz ./

    posted @ 2010-03-18 17:21 BlakeSu 閱讀(203) | 評論 (0)編輯 收藏

    websphere6.1 設定虛擬機參數

    Application Servers > server1 > Process Definition > Java Virtual Machine > Custom Properties

    虛擬機參數在命令行的形式為 -Dproperty=value,在程序中可以用System.getProperty("property")取值。
    利用這個特性可以對程序運行進行控制,避免代碼的修改。




    posted @ 2010-03-15 09:57 BlakeSu 閱讀(259) | 評論 (0)編輯 收藏

    firefox3.6擴展和插件安裝位置

    地址欄輸入about:support,在打開的頁面有打開配置文件夾的按鈕;
    擴展在Extensions文件夾下,插件在安裝文件夾下的plugin和其他目錄。

    posted @ 2010-03-15 09:22 BlakeSu 閱讀(419) | 評論 (0)編輯 收藏

    xfire 動態客戶端


    import java.net.URL;

    import org.codehaus.xfire.client.Client;

    public class XfireClient
    {

        
    public static void main(String[] args)
        {
            DyClient();
        }

        
    /**
         * You get a DynamicClient when you create a Client with the URL of a WSDL
         
    */
        
    public static void DyClient()
        {
            
    try
            {
                Client client 
    = new Client(
                        
    new URL(
                                
    "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl"));
                Object[] results 
    = client.invoke("qqCheckOnline",
                        
    new Object[] { "31506173" });
                System.out.println((String) results[
    0]);

            }
            
    catch ( Exception e)
            {
                e.printStackTrace();
            }
        }
    }




    必須jar:
    commons-codec-1.3.jar
    commons-httpclient-3.0.jar
    commons-logging-1.0.4.jar
    jdom-1.0.jar
    wsdl4j-1.6.1.jar
    xfire-all-1.2.6.jar
    XmlSchema-1.1.jar

    posted @ 2010-03-08 16:00 BlakeSu 閱讀(339) | 評論 (0)編輯 收藏

    漢字與utf8編碼相互轉換


    import java.io.UnsupportedEncodingException;


    public class UTF {

        public static void main(String[] args) {
            String s 
    = "非常好";
            
    try {
                
    byte[] b = s.getBytes("UTF-8");
                
    for(int i=0; i< b.length; i++){
                    System.out.println(Integer.toHexString(b[i]).substring(
    6));
                    
                }
                System.out.println(
    new String(b, "UTF-8"));

            } 
    catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } 
            

        }

    }

    輸出:
    e9
    9d
    9e
    e5
    b8
    b8
    e5
    a5
    bd
    非常好

    posted @ 2010-02-26 13:39 BlakeSu 閱讀(199) | 評論 (0)編輯 收藏

    狀態模式與策略模式的重要區別

    是否需要在State類或Strategy類中訪問Context.
    狀態模式通常需要調用Context中的方法,以改變Context的狀態。
    Strategy通常不需要。

    posted @ 2010-02-23 17:50 BlakeSu 閱讀(326) | 評論 (0)編輯 收藏

    linux正則表達式


    記號 含義 舉例 匹配
    . 任何字符 a.. a后兩個字符
    ^ 行首 ^wood 位于行首的wood
    $ 行尾 x$
    ^INSERT$
    ^$
    位于行尾的x
    只包含字符串INSERT的行
    不包含任何字符的行
    * 前導的正則表達式重復0或若干次 x*
    xx*
    .*
    w.*s
    0或若干次連續的x
    1或多個連續的x
    0或若干個字符
    以w開始,s結尾的任何字符串
    [字符表] 字符表中的任一 [tT]
    [a-z]
    [a-zA-Z]
    小寫或大寫的t
    小寫字母
    字母(大寫或小寫)
    [^字符表] 任一不在字符表中的字符 [^0-9]
    [^a-zA-Z]
    任何數字
    非字母
    \{min,max\} 前導的正則表達式重復至少min次,最多max次 X\{1,5\}
    [0-9]\{3,9\}
    [0-9]\{3\}
    [0-9]\{3,\}
    最少1個,最多5個x
    3到9個數字
    正好3個數字
    至少3個數字
    \(…\) 將小括號中匹配的字符串存儲到下一個寄存器中(1-9) ^\(.\)
    ^\(.\)\1
    行中第1個字符存到1號寄存器
    行首兩個字符,且它們相同

    如下命令含有正則表達式: cut paste sed tr grep sort uniq

    posted @ 2010-02-11 15:01 BlakeSu 閱讀(274) | 評論 (0)編輯 收藏

    開源框架(spring struts2 tomcat)源碼下載地址

    spring

    svn checkout https://src.springframework.org/svn/spring-framework/trunk spring-framework

      ant resolve

    struts2

    svn checkout http://svn.apache.org/repos/asf/struts/struts2/trunk struts2
    svn checkout http://svn.apache.org/repos/asf/struts/xwork/trunk/ xwork

     mvn install
     mvn eclipse:eclipse

    tomcat6

    svn checkout http://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk tc6.0.x
     1.下載ant 1.6.x
     2. 命令行下執行 ant download,下載依賴jar.

    posted @ 2010-02-07 10:41 BlakeSu 閱讀(461) | 評論 (0)編輯 收藏

    spring 計時器類 StopWatch

     StopWatch

    posted @ 2010-02-05 16:08 BlakeSu 閱讀(540) | 評論 (0)編輯 收藏

    [李琨]REST的主要優勢到底是什么?

    在JavaEye論壇上回答網友joyjiang的疑問:“REST的優勢到底是什么?開發效率?文檔的管理?url的直觀?還是其它的什么優勢呢?”

    REST的主要優勢在我看來其實在于它是一種對于服務器的更加有效的抽象方式。

    對于基于網絡的應用來說,你怎么樣看待服務器,就會產生什么樣的架構風格,隨之產生與該架構風格相關的交互模式。

    RPC架構風格將服務器看作是由一些過程組成,客戶端調用這些過程來執行特定的任務。SOAP就是RPC風格的一種架構。過程是動詞性的(做某件事),因此RPC建模是以動詞為中心的。

    分布式對象架構風格認 為服務器是由一些對象和對象上的方法組成,客戶端通過調用這些對象上的方法來執行特定的任務。并且客戶端調用這些對象上的方法應該就像是調用本地對象上的 方法一樣,這樣開發就可以完全按照統一的面向對象方法來做。但是很可惜,這樣的抽象并不是很有效,因為分布式對象與本地對象存在著巨大的本質差別,想要掩 蓋這些差別很多時候甚至是有害無益的。

    REST架構風格并 沒有試圖掩蓋這些差別,而是將服務器抽象為一組離散資源的集合。資源是一個抽象的概念,而不是代表某個具體的東西。注意:要真正理解REST,就一定要增 強自己的抽象思維能力,充分理解到資源是抽象的。如果完全不具有抽象思維的能力,一定要將資源與數據庫中的一張表或服務器端的一個文件(HTML、 Servlet、JSP、etc.)一一掛起鉤來,就無法真正理解REST了。資源是名詞性的,因此REST建模是以名詞為中心的。

    上述 是目前基于網絡的應用的主要的三種抽象方式。這三種不同的抽象方式會嚴重影響客戶端與服務器的交互模式,而不同交互模式的交互效率差別相當大。分布式對象 的交互模式很多時候效率很低,因為掩蓋了分布式對象與本地對象的差別,很多時候都會導致細粒度的API(需要一再強調才能讓一些不明就里的架構初哥按照正 確的方式來做設計)。實踐已經證明,與RPC和分布式對象相比,REST是一種對于服務器更加有效的抽象方式,將會帶來粒度更大和更有效率的交互模式。這 樣的效果與Fielding設計REST的初衷是吻合的,REST就是專門為交互的性能和可伸縮性進行過優化的一種架構風格。而SOAP在設計的時候優先 考慮的從來不是性能和可伸縮性,而是互操作性。除非出現奇跡,否則你種什么,就應該長出來什么。你種的是瓜,長出來的就是瓜;你種的是豆,長出來的就是 豆。

    Fielding寫到:“REST提供了一組架構約束,當作為一個整體來應用時,強調組件交互的可伸縮性、接口的通用性、組件的獨立部署、以及用來減少交互延遲、增強安全性、封裝遺留系統的中間組件。

    有 人認為REST不是面向對象的,其實REST雖然沒有分布式對象那么面向對象,在我看來至少比RPC更加面向對象。按照《企業應用架構模式》,以動詞為中 心建模是什么?是不是就是事務腳本?以名詞為中心建模是什么?是不是就是領域模型?這就扯遠了,網絡通信是否一定需要實現為面向對象的形式,我認為是不需 要的。

    “REST的主要優勢在我看來其實在于它是一種對于服務器的更加有效的抽象方式。”
    這句話等于是,我先把一個骨架放在這里,還沒有用血肉來充實它,也就是還沒有舉出具體的實例來。具體的實例以后我們還需要來詳細討論。REST是非常簡練的,同時又是一種非常強大的抽象方式,在我看來就是從根本上簡化Web開發的一味良藥。

    posted @ 2010-02-05 10:57 BlakeSu 閱讀(237) | 評論 (0)編輯 收藏

    取用戶所有表的所有索引

    select index_name from dba_indexes where table_name
    in (select table_name from user_tables)

    posted @ 2010-01-29 10:08 BlakeSu 閱讀(145) | 評論 (0)編輯 收藏

    oracle優化新知識

    1.位圖索引用于數據倉庫,不能用于普通系統
    2.使用組合索引. 當大量字段同同時作為過濾條件時,使用組合索引會大大提高性能。
    建立組合索引時,注意小基數字段在前,大基數字段在后。
    3.同一字段出現在不同表要保持類型一致(確有需要,可使用函數索引)
    4.使用count(*)
    5.使用返回單個結果的查詢改寫外連接能取得較好的性能

    posted @ 2010-01-22 13:22 BlakeSu 閱讀(194) | 評論 (0)編輯 收藏

    Oracle中表連接的運行原理

    Oracle優化器會自動選擇以下三種方式的一種運行表連接,但在數據環境上配合強化選擇合適的方式或強制使用某種方式是SQL優化的需要:
     
       NESTED LOOP

    對于被連接的數據子集較小的情況,nested loop連接是個較好的選擇。nested loop就是掃描一個表,每讀到一條記錄,就根據索引去另一個表里面查找,沒有索引一般就不會是 nested loops。

    一般在nested loop中, 驅動表滿足條件結果集不大,被驅動表的連接字段要有索引,這樣就走nested loop。如果驅動表返回記錄太多,就不適合nested loops了。如果連接字段沒有索引,則適合走hash join,因為不需要索引。

    可用ordered提示來改變優化器默認的驅動表,可用USE_NL(table_name1 table_name2)提示來強制使用nested loop。

    HASH JOIN

    hash join是優化器做大數據集連接時的常用方式。優化器掃描小表(或數據源),利用連接鍵(也就是根據連接字段計算hash 值)在內存中建立hash表,然后掃描大表,每讀到一條記錄就來探測hash表一次,找出與hash表匹配的行。

    當 小表可以全部放入內存中,其成本接近全表掃描兩個表的成本之和。如果表很大不能完全放入內存,這時優化器會將它分割成若干不同的分區,不能放入內存的部分 就把該分區寫入磁盤的臨時段,此時要有較大的臨時段從而盡量提高I/O 的性能。臨時段中的分區都需要換進內存做hash join。這時候成本接近于全表掃描小表+分區數*全表掃描大表的代價和。

    至于兩個表都進行分區,其好處是可以使用parallel query,就是多個進程同時對不同的分區進行join,然后再合并。但是復雜。

    使用hash join時,HASH_AREA_SIZE初始化參數必須足夠的大,如果是9i,Oracle建議使用SQL工作區自動管理,設置WORKAREA_SIZE_POLICY 為AUTO,然后調整PGA_AGGREGATE_TARGET即可

    以下條件下hash join可能有優勢:

    兩個巨大的表之間的連接。

    在一個巨大的表和一個小表之間的連接。

    可用ordered提示來改變優化默認的驅動表,可用USE_HASH(table_name1 table_name2)提示來強制使用hash join。

    SORT MERGE JOIN

    sort merge join的操作通常分三步:對連接的每個表做table access full;對table access full的結果進行排序;進行merge join對排序結果進行合并。sort merge join性能開銷幾乎都在前兩步。一般是在沒有索引的情況下,9i開始已經很少出現了,因為其排序成本高,大多為hash join替代了

    通常情況下hash join的效果都比sort merge join要好,然而如果行源已經被排過序,在執行sort merge join時不需要再排序了,這時sort merge join的性能會優于hash join。

    在全表掃描比索引范圍掃描再通過rowid進行表訪問更可取的情況下,sort merge join會比nested loops性能更佳。

    可用USE_MERGE(table_name1 table_name2)提示強制使用sort merge join。

    posted @ 2010-01-15 12:05 BlakeSu 閱讀(376) | 評論 (0)編輯 收藏

    java 運行windows命令 并獲取輸出

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;

    public class ProcessTest {

        
    public static void main(String[] args) {
            
             ProcessBuilder pb 
    = new  ProcessBuilder ( "tasklist");  
             try {
                Process process 
    = pb.start();
                InputStream fis 
    = process.getInputStream();
                BufferedReader br 
    = new BufferedReader(new InputStreamReader(fis));

                String line 
    = null;
                StringBuffer cmdout 
    = new StringBuffer();
                
    while ((line = br.readLine()) != null) {
                    cmdout.append(line).append(
    "\n");
                }
                System.out.println(cmdout.toString().trim());
            } 
    catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    輸出如下:

    圖像名                       PID 會話名           會話#       內存使用
    ========================= ====== ================ ======== ============
    System Idle Process            0 Console                 0         28 K
    System                         4 Console                 0        324 K
    smss.exe                    1076 Console                 0        812 K
    csrss.exe                   1152 Console                 0      3,296 K
    winlogon.exe                1176 Console                 0     31,580 K
    services.exe                1220 Console                 0      4,684 K
    lsass.exe                   1232 Console                 0      1,672 K
    svchost.exe                 1408 Console                 0      6,236 K
    svchost.exe                 1496 Console                 0      5,036 K
    svchost.exe                 1656 Console                 0     38,656 K
    spoolsv.exe                 1872 Console                 0      8,000 K
    explorer.exe                 332 Console                 0     18,888 K
    avp.exe                      376 Console                 0     24,960 K
    db2dasrrm.exe                460 Console                 0     34,652 K
    TSVNCache.exe                672 Console                 0     12,476 K
    igfxtray.exe                1380 Console                 0      7,344 K
    hkcmd.exe                   1236 Console                 0      4,056 K
    igfxpers.exe                1428 Console                 0      3,468 K
    db2mgmtsvc.exe              1444 Console                 0     10,072 K
    RTHDCPL.exe                 1460 Console                 0     32,480 K
    igfxsrvc.exe                1572 Console                 0      3,772 K
    avp.exe                     1680 Console                 0      6,008 K
    db2systray.exe              1700 Console                 0     32,512 K
    ctfmon.exe                  1780 Console                 0      4,892 K
    picpick.exe                 1984 Console                 0      3,600 K
    QQ.exe                      2024 Console                 0     34,648 K
    dsNcService.exe              264 Console                 0      3,880 K
    365日歷.EXE                 1952 Console                 0     43,788 K
    CLCL.exe                    1028 Console                 0      8,252 K
    klnagent.exe                1052 Console                 0      3,196 K
    thunderbird.exe              352 Console                 0     38,692 K
    rtxc.exe                     472 Console                 0     29,968 K
    db2rcmd.exe                 1836 Console                 0     11,832 K
    TXPlatform.exe              2488 Console                 0      3,808 K
    firefox.exe                 2724 Console                 0    195,912 K
    cmd.exe                     2716 Console                 0         52 K
    sh.exe                      3936 Console                 0        152 K
    conime.exe                  2752 Console                 0      3,424 K
    eclipse.exe                 3060 Console                 0      2,592 K
    JAVAW.EXE                   2984 Console                 0    446,692 K
    EXCEL.EXE                   3232 Console                 0      1,936 K
    wmiprvse.exe                4084 Console                 0      6,368 K
    JAVAW.EXE                    320 Console                 0      6,860 K
    tasklist.exe                2936 Console                 0      4,812 K

    當運行其他命令 ,如dir等時,用如下寫法:

     
    ProcessBuilder pb = new  ProcessBuilder ( "cmd""/c""dir");


    posted @ 2010-01-13 13:49 BlakeSu 閱讀(590) | 評論 (0)編輯 收藏

    Ubuntu9.10正確有效關閉IPV6的方法

    Ubuntu下上網解析DNS慢有很大程度上是和IPV6有關,而目前國內大部分地方都還沒有IPV6網絡,所以一般用戶應該需要關閉IPV6

    網上流傳著很多IPV6的關閉方法,但是經過測試大部分都是針對老版本的,而且效果不好。

    這里提供一種方法作為參考

    /proc/sys/net/ipv6/conf/lo/disable_ipv6

    這個檔案,用cat指令可以看到 0 這個數字,將他設定為1就可以了。
    因為已經將ipv6編入kernel,因此在proc里面就可以看得到相關的設定。

    設定的方式有很多種,有的是用echo 1 >> [路徑]/檔桉名稱
    的方式,這種方式是每次開機以后就得要打一次。
    所以延伸出第二個方法,在rcS.d里面設定一個連結,去執行這個指令的script。
    第3個方法,就是設定sysctl.conf檔桉,也是最正統的做法。
    位置在
    /etc/sysctl.conf
    這個檔桉可以設定很多,包括要當成NAT時的封包轉發等等。
    要設定
    /proc/sys/net/ipv6/conf/lo/disable_ipv6
    這個檔桉,就是在sysctl.conf里面加上

    net.ipv6.conf.lo.disable_ipv6 = 1

    posted @ 2010-01-09 14:53 BlakeSu 閱讀(565) | 評論 (0)編輯 收藏

    主站蜘蛛池模板: 亚洲自国产拍揄拍| 97公开免费视频| 亚洲视频在线观看2018| 国产亚洲精品a在线观看| 国产精品1024永久免费视频| 国产免费区在线观看十分钟| 国产精品亚洲综合久久| 久久亚洲中文字幕精品有坂深雪| 亚洲精品国产高清不卡在线| 精品剧情v国产在免费线观看| 在线日本高清免费不卡| a级成人毛片免费视频高清| 免费看一级毛片在线观看精品视频 | 日本一道在线日本一道高清不卡免费| 99久久免费看国产精品| 精品熟女少妇aⅴ免费久久| 亚洲av片在线观看| 亚洲人成77777在线观看网| 亚洲精品自拍视频| 亚洲AV无码成人精品区蜜桃 | 三级毛片在线免费观看| 在线观看亚洲电影| 亚洲精品美女久久7777777| 亚洲国产日韩综合久久精品| 亚洲日本乱码一区二区在线二产线 | 亚洲国产精品成人一区| 国产人妖ts在线观看免费视频| 成年女人免费视频播放77777 | 亚洲美女在线观看播放| 亚洲国产综合91精品麻豆| 亚洲AV无码一区二区二三区软件| 亚洲乱码一区二区三区在线观看| 亚洲区不卡顿区在线观看| 亚洲av无码天堂一区二区三区| 国产免费黄色大片| 人人狠狠综合久久亚洲高清| 四只虎免费永久观看| 亚洲av成人一区二区三区在线观看 | 亚洲人成电影福利在线播放| 亚洲精品亚洲人成在线观看| 亚洲宅男天堂在线观看无病毒|