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

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

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

    少年阿賓

    那些青春的歲月

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

    #

    package org.abin.lee;

    import java.security.cert.CertificateException;
    import java.security.cert.X509Certificate;

    import javax.net.ssl.X509TrustManager;
      

    /**    
     * 自定義的認證管理類。    
     *     
     * @author JAVA世紀網(wǎng)(java2000.net)    
     *     
     */     
    class Java2000TrustManager implements X509TrustManager {      
      Java2000TrustManager() {      
        // 這里可以進行證書的初始化操作      
      }      
      // 檢查客戶端的可信任狀態(tài)      
      public void checkClientTrusted(X509Certificate chain[], String authType) throws CertificateException {      
        System.out.println("檢查客戶端的可信任狀態(tài)...");      
      }      
      // 檢查服務器的可信任狀態(tài)      
      public void checkServerTrusted(X509Certificate chain[], String authType) throws CertificateException {      
        System.out.println("檢查服務器的可信任狀態(tài)");      
      }      
      // 返回接受的發(fā)行商數(shù)組      
      public X509Certificate[] getAcceptedIssuers() {      
        System.out.println("獲取接受的發(fā)行商數(shù)組...");      
        return null;      
      }      
    }    








    package org.abin.lee;

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.net.Socket;

    import javax.net.ssl.SSLContext;
    import javax.net.ssl.SSLSocketFactory;
    import javax.net.ssl.TrustManager;
    import javax.net.ssl.X509TrustManager;

    /**
     * JAVA操作SSL協(xié)議,通過Socket訪問Https的程序代碼例子。
     *
     * @author JAVA世紀網(wǎng)(java2000.net)
     *
     */
    public class ReadHttpsURL {
     // 默認的HTTPS 端口
     static final int HTTPS_PORT = 443;

     public static void main(String argv[]) throws Exception {
      // 受訪主機
      String host = "  // 受訪的頁面
      String url = "/adsense/?sourceid=aso&subid=ZH_CN-ET-AS-ADSBY6&medium=link&hl=zh_CN";
      // 自定義的管理器
      X509TrustManager xtm = new Java2000TrustManager();
      TrustManager mytm[] = { xtm };
      // 得到上下文
      SSLContext ctx = SSLContext.getInstance("SSL");
      // 初始化
      ctx.init(null, mytm, null);
      // 獲得工廠
      SSLSocketFactory factory = ctx.getSocketFactory();
      // 從工廠獲得Socket連接
      Socket socket = factory.createSocket(host, HTTPS_PORT);
      // 剩下的就和普通的Socket操作一樣了
      BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
        socket.getOutputStream()));
      BufferedReader in = new BufferedReader(new InputStreamReader(
        socket.getInputStream()));
      out.write("GET " + url + " HTTP/1.0\n\n");
      out.flush();
      System.out.println("start   work!");
      String line;
      StringBuffer sb = new StringBuffer();
      while ((line = in.readLine()) != null) {
       sb.append(line + "\n");
      }
      out.close();
      in.close();
      System.out.println(sb.toString());
     }
    }





    http://ming-fanglin.iteye.com/blog/574596

    posted @ 2012-08-16 00:35 abin 閱讀(984) | 評論 (0)編輯 收藏

    Here’s a simple Java HTTPS client to demonstrate the use of HttpsURLConnection class to print a https URL content and certificate detail.

    Access https URL : https://www.google.com/


    package com.mkyong.client;
     
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.security.cert.Certificate;
    import java.io.*;
     
    import javax.net.ssl.HttpsURLConnection;
    import javax.net.ssl.SSLPeerUnverifiedException;
     
    public class HttpsClient{
     
       public static void main(String[] args)
       {
            new HttpsClient().testIt();
       }
     
       private void testIt(){
     
          String https_url = "https://www.google.com/";
          URL url;
          try {
     
    	     url = new URL(https_url);
    	     HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
     
    	     //dumpl all cert info
    	     print_https_cert(con);
     
    	     //dump all the content
    	     print_content(con);
     
          } catch (MalformedURLException e) {
    	     e.printStackTrace();
          } catch (IOException e) {
    	     e.printStackTrace();
          }
     
       }
     
       private void print_https_cert(HttpsURLConnection con){
     
        if(con!=null){
     
          try {
     
    	System.out.println("Response Code : " + con.getResponseCode());
    	System.out.println("Cipher Suite : " + con.getCipherSuite());
    	System.out.println("\n");
     
    	Certificate[] certs = con.getServerCertificates();
    	for(Certificate cert : certs){
    	   System.out.println("Cert Type : " + cert.getType());
    	   System.out.println("Cert Hash Code : " + cert.hashCode());
    	   System.out.println("Cert Public Key Algorithm : " + cert.getPublicKey().getAlgorithm());
    	   System.out.println("Cert Public Key Format : " + cert.getPublicKey().getFormat());
    	   System.out.println("\n");
    	}
     
    	} catch (SSLPeerUnverifiedException e) {
    		e.printStackTrace();
    	} catch (IOException e){
    		e.printStackTrace();
    	}
     
         }
     
       }
     
       private void print_content(HttpsURLConnection con){
    	if(con!=null){
     
    	try {
     
    	   System.out.println("****** Content of the URL ********");			
    	   BufferedReader br = 
    		new BufferedReader(
    			new InputStreamReader(con.getInputStream()));
     
    	   String input;
     
    	   while ((input = br.readLine()) != null){
    	      System.out.println(input);
    	   }
    	   br.close();
     
    	} catch (IOException e) {
    	   e.printStackTrace();
    	}
     
           }
     
       }
     
    }

    Output…

    Response Code : 200
    Cipher Suite : SSL_RSA_WITH_RC4_128_SHA
     
    Cert Type : X.509
    Cert Hash Code : 7810131
    Cert Public Key Algorithm : RSA
    Cert Public Key Format : X.509
     
    Cert Type : X.509
    Cert Hash Code : 6042770
    Cert Public Key Algorithm : RSA
    Cert Public Key Format : X.509
     
    ****** Content of the URL ********
    <!doctype html><html><head><meta http-equiv="content-type" ......
    posted @ 2012-08-16 00:17 abin 閱讀(1926) | 評論 (1)編輯 收藏

     
    京-pk發(fā)型不亂CEO<wuraolong@126.com>  23:33:00
      public String executeHttpRequest(String url, String requestContent,Log log) {
            Log logHttp= log;  //logHttp對應的可能是開放平臺、酒店開放平臺、酒店
            HttpClient client = new HttpClient();
            PostMethod postMethod = new PostMethod(url);
            try {
                postMethod.setRequestEntity(new StringRequestEntity(requestContent, "text/xml; charset=" + charSet, charSet));
                postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
                postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, charSet);
                postMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, soTimeOut);
                int statusCode = client.executeMethod(postMethod);
                BufferedReader in = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream(), charSet));
                StringBuffer sb = new StringBuffer();
                String line;
                while ((line = in.readLine()) != null) {
                    sb.append(line);
                }
                in.close();
                if (statusCode != HttpStatus.SC_OK) {
                    logHttp.error("Method:HttpClientUtil.executeHttpRequest---->請求返回狀態(tài)不為200,url:" + url + ",返回結(jié)果:" + sb.toString());
                    return "";
                }
                 logHttp.info("Method:HttpClientUtil.executeHttpRequest---->請求返回狀態(tài)為200,url:" + url + ",返回結(jié)果:" + sb.toString());
                return sb.toString();
            }
            catch (Exception e) {
                logHttp.error("Method:HttpClientUtil.executeHttpRequest---->發(fā)生異常!請檢查網(wǎng)絡(luò)和參數(shù)", e);
            }
            finally {
                postMethod.releaseConnection();
            }
            return null;
        }
    }
    posted @ 2012-08-15 23:43 abin 閱讀(1075) | 評論 (0)編輯 收藏

    完美的解決方法從辟謠開始:
    1)JDOM是否生成UTF-8的文件與Format是否設(shè)置無關(guān),只有輸出其他字符編碼才需要設(shè)置,見下面的注釋。
    2)JDOM輸出UTF-8文件亂碼的根本原因并非在JDOMAPI,而是在JDK。
    具體描述:
        JDOM的輸出類XMLOutputter有兩個output接口,除了都具有一個Document參數(shù)外,分別接受Writer和 OutputStream參數(shù)。
        這給我們一個錯覺,兩個接口可以任意使用。
        首先我們用output(doc,System.out)來做測試,此時得到亂碼,
          然后我們改為output(doc,new PrintWriter(System.out))來測試,輸出不是亂碼,
          也就是說在控制臺的時候一定要用一個Writer接口包裝一下。
         然后我們用output(doc,new FileWriter(path))來做測試,結(jié)果卻得到亂碼,
          然后我們改為output(doc,new FileOutputStream(path))來測試,輸出不是亂碼,
          也就是說在輸出文件的時候一定要用一個OutputStream接口包裝一下。
         瘋了吧?呵呵,很搞笑是吧。經(jīng)過到JDOM的源碼中調(diào)試,發(fā)現(xiàn)沒有任何問題,問題出在了JDK里面。
    JDK內(nèi)的對應接口處理:
    1)PrintWriter類有參數(shù)為OutputStream的構(gòu)造方法,因此可以從System.out包裝到PrintWriter
    2)FileWriter類沒有參數(shù)為OutputStream的構(gòu)造方法,因此不能從FileOutputStream包裝到 FileWriter
    3)如果PrintWriter類用了參數(shù)為Writer的構(gòu)造方法(Writer實現(xiàn)為FileWriter),最后輸出也是亂碼
    4)如果用一個FileOutputStream來包裝一個控制臺輸出,也是亂碼
    因此,對于JDK內(nèi)的各種輸出體系,各種InputStream、OutputStream、reader和writer要充分認識,否則極容易出現(xiàn)一些意想不到的問題。


    posted @ 2012-08-15 09:34 abin 閱讀(680) | 評論 (0)編輯 收藏

    -- Create table
    create table ABING1
    (
      ID         INTEGER not null,
      CREATETIME DATE default sysdate not null,
      FIRSTNAME  NVARCHAR2(100) not null,
      LASTNAME   CLOB not null,
      MIDDLENAME NCLOB not null
    )
    tablespace USERS
      pctfree 10
      initrans 1
      maxtrans 255
      storage
      (
        initial 64K
        minextents 1
        maxextents unlimited
      );
    -- Create/Recreate primary, unique and foreign key constraints
    alter table ABING1
      add constraint PK_ABING primary key (ID)
      using index
      tablespace USERS
      pctfree 10
      initrans 2
      maxtrans 255
      storage
      (
        initial 64K
        minextents 1
        maxextents unlimited
      );




    create or replace procedure abin55(abing in varchar2,abin out sys_refcursor)
    as
    begin
    declare
    createtime date:=to_date(abing,'yyyy:MM:dd HH24:MI:SS');
    cursor mycur is select * from abing1 t where t.createtime=createtime;
    abin mycur%rowtype;
    begin
    open mycur;
    loop
         fetch mycur into abin;
         exit when mycur%NOTFOUND;
    end loop;
    close mycur;
    end;
    end;
    posted @ 2012-08-15 00:57 abin 閱讀(526) | 評論 (0)編輯 收藏

    //建表:
    -- Create table
    create table EMP
    (
      ID         NUMBER,
      ENAME      VARCHAR2(50),
      EMPNO      VARCHAR2(50),
      SALARY     NUMBER(10),
      DEPTNO     VARCHAR2(50),
      CREATETIME DATE default sysdate
    )
    tablespace USERS
      pctfree 10
      initrans 1
      maxtrans 255
      storage
      (
        initial 64K
        minextents 1
        maxextents unlimited
      );


    建立歷史表:
    create table emp_his as select * from emp where 1=2



    建立oracle觸發(fā)器:
    create or replace trigger tri_del_emp
    before delete on emp
    for each row
    begin
    insert into emp_his(id,ename,empno,salary,deptno,createtime) values
    (:old.id,:old.ename,:old.empno,:old.salary,:old.deptno,:old.createtime);
    end;


    執(zhí)行測試操作:
    delete emp where id=8

    這個時候,歷史表,信息已經(jīng)插入進去了,呵呵


    posted @ 2012-08-14 00:01 abin 閱讀(301) | 評論 (0)編輯 收藏

    建立異常表:

    -- Create table
    create table ORACLEEXCEPTION
    (
      ID          VARCHAR2(36),
      CREATETIME  DATE,
      SQLCODE1    NVARCHAR2(300),
      SQLERRM1    NVARCHAR2(300),
      MYEXCEPTION NVARCHAR2(100)
    )
    tablespace USERS
      pctfree 10
      initrans 1
      maxtrans 255
      storage
      (
        initial 64K
        minextents 1
        maxextents unlimited
      );

     

     

    編寫oracle--function:

    create or replace function getabin(abin in varchar2)
    return varchar2
    is
    result varchar2(50);
    sqlcode2 nvarchar2(500):='';
    sqlerrm2 nvarchar2(500):='';
    myexception nvarchar2(500):='';
    exception1 exception;
    begin
    if(abin is not null) then
    select count(1) into result from bing1 t where t.name1 like abin;
    return(result);
    elsif(abin is null) then
    result:='there is a defined exception';
    raise exception1;
    end if;

    exception
    when exception1 then
    sqlcode2:=sqlcode;
    sqlerrm2:=sqlerrm;
    begin
    insert into oracleexception(id,createtime,sqlcode1,sqlerrm1,myexception) values (sys_guid(),sysdate,sqlcode2,sqlerrm2,'exception1');
    commit;
    end;
    return(result);
    when others then
    result:='there is a other exception';
    sqlcode2:=sqlcode;
    sqlerrm2:=sqlerrm;
    begin
    insert into oracleexception(id,createtime,sqlcode1,sqlerrm1,myexception) values (sys_guid(),sysdate,sqlcode2,sqlerrm2,'others');
    commit;
    end;
    return(result);
    end;

     

     

     

    測試oracle--function代碼:

    declare 
    ename varchar2(50):='';
    result varchar2(50);
    begin
    result:=getabin(ename);
    dbms_output.put_line(result);
    end;

     

    posted @ 2012-08-13 23:34 abin 閱讀(846) | 評論 (0)編輯 收藏

    ORACLE PL/SQL編程-異常錯誤處理(下)
    http://hi.baidu.com/mylin/blog/item/5a3ca6c2b321fd0c0ef4779b.html

    ORACLE PL/SQL編程之八:

    把觸發(fā)器說透
    http://www.cnblogs.com/huyong/archive/2011/04/27/2030466.html

    posted @ 2012-08-13 01:10 abin 閱讀(324) | 評論 (0)編輯 收藏

    oracle函數(shù)一:
    create or replace function getBin
    return varchar2
    is
    result varchar2(50);
    begin
    select count(1) into result from bing1;
    return(result);
    end;

    測試代碼:
    declare
    result varchar2(50);
    begin
    result:=getBin;
    dbms_output.put_line(result);
    end;

    oracle函數(shù)二:
    create or replace function getBin3(ename in varchar2)
    return varchar2
    is
    result varchar(50);
    begin
    select count(1) into result from bing1 t where t.name1 like '%'||ename||'%';
    return(result);
    end;

    測試代碼二:
    declare
    result varchar2(50);
    ename varchar2(10):='a';
    begin
    result:=getBin3(ename);
    dbms_output.put_line(result);
    end;


    posted @ 2012-08-12 21:01 abin 閱讀(334) | 評論 (0)編輯 收藏

    函數(shù)調(diào)用限制
    1、SQL語句中只能調(diào)用存儲函數(shù)(服務器端),而不能調(diào)用客戶端的函數(shù)
    2、SQL只能調(diào)用帶有輸入?yún)?shù),不能帶有輸出,輸入輸出函數(shù)
    3、SQL不能使用PL/SQL的特有數(shù)據(jù)類型(boolean,table,record等)
    4、SQL語句中調(diào)用的函數(shù)不能包含INSERT,UPDATE和DELETE語句

    1.function函數(shù)的語法如下:

          create or replace function function_name (

           argu1 [mode1] datatype1, --定義參數(shù)變量

           argu2 [mode2] datatype2 --定義參數(shù)變量

       ) return datatype --定義返回的數(shù)據(jù)類型

      is 

      begin

      end;

    執(zhí)行 var v1 varchar2(100)
          exec :v1:=function_name

    2.不帶任何參數(shù)的定義

    create or replace function get_user 

    return varchar2 

    is 

    Result varchar2(50); --定義變量

    begin 

    select username into Result from user_users; 

    return(Result); --返回值

    end get_user;

    3.帶有in參數(shù)的

    create or replace function get_sal(

    empname in varchar2

    ) return number 

    is 

    Result number; 

    begin 

    select sal into Result from emp where ename=empname; 

    return(Result); 

    end;

    執(zhí)行: SQL> var sal number
    SQL> exec :sal:=get_sal('scott');

    4.帶out參數(shù)的

    create or replace function get_info(

    e_name varchar2,

    job out varchar2

    ) return number 

    Is

    Result number; 

    begin 

    select sal,job into Result,job from emp where ename=e_name;
    return(Result);
    end;

    執(zhí)行: SQL> var job varchar2(20)
    SQL> var dname varchar2(20)
    SQL> exec :dname:=get_info('SCOTT',:job)

    5.帶in out參數(shù)的

    6.函數(shù)調(diào)用舉例

    create or replace function f_sys_getseqid(
        v_seqname           IN VARCHAR2,
        v_provincecode      IN VARCHAR2    --省編碼
    ) return Varchar2
    IS
        iv_date             VARCHAR2(8);
        iv_seqname          VARCHAR2(50);
        iv_sqlstr           VARCHAR2(200);
        iv_seq              VARCHAR2(8);
        iv_seqid            VARCHAR2(16);
    BEGIN
        iv_seqname := LOWER(TRIM(v_seqname));
        iv_sqlstr := 'SELECT '||iv_seqname||'.nextval FROM DUAL';
        EXECUTE IMMEDIATE iv_sqlstr INTO iv_seq;--執(zhí)行動態(tài)的sql語句,執(zhí)行相似的一組語句
        IF v_seqname = 'SEQ_FUNCROLE_ID' THEN
          iv_seqid:= 'ESS' || LPAD(iv_seq,5,'0');
        ELSE
          SELECT substrb(v_provincecode,1,2)||TO_CHAR(SYSDATE,'yymmdd') INTO iv_date FROM DUAL;
          iv_seqid:= iv_date || LPAD(iv_seq,8,'0');
        END IF;
        RETURN iv_seqid;
    EXCEPTION
        WHEN OTHERS THEN
        RETURN NULL;
    END;

      調(diào)用方式如下:

        SELECT TO_NUMBER(F_SYS_GETSEQID('SEQ_TERMTRADE_ID', V_PROVINCE_CODE)) INTO V_BATCH_ID FROM DUAL;

       EXECUTE IMMEDIATE的說明:執(zhí)行動態(tài)的sql語句。

    posted @ 2012-08-12 20:42 abin 閱讀(33343) | 評論 (2)編輯 收藏

    僅列出標題
    共50頁: First 上一頁 33 34 35 36 37 38 39 40 41 下一頁 Last 
    主站蜘蛛池模板: 日本黄页网站免费| 久久国产乱子精品免费女| 亚洲人AV在线无码影院观看| 亚洲六月丁香六月婷婷色伊人 | 可以免费观看的毛片| 久久久久免费视频| 中文字幕在线视频免费观看| GOGOGO免费观看国语| 在线观看免费视频一区| 免费精品久久天干天干| 久久这里只精品国产免费10| 国产成人精品无码免费看| 8x网站免费入口在线观看| 四虎免费影院ww4164h| 日本XXX黄区免费看| 日本免费中文字幕在线看| 又粗又硬又大又爽免费视频播放| 全黄性性激高免费视频| 亚洲日韩在线观看免费视频| 亚洲精品字幕在线观看| 日批视频网址免费观看| 免费网站观看WWW在线观看| 无码国产精品一区二区免费vr | 叮咚影视在线观看免费完整版| 久久精品免费观看| 亚洲人成免费电影| 午夜毛片不卡高清免费| 国产一区二区免费在线| 在线精品亚洲一区二区小说| 97亚洲熟妇自偷自拍另类图片| 亚洲香蕉久久一区二区| 噜噜噜亚洲色成人网站| 免费无码又爽又刺激网站 | 激情婷婷成人亚洲综合| 国产精品九九久久免费视频| 免费91麻豆精品国产自产在线观看 | 亚洲日韩精品A∨片无码| 亚洲综合无码一区二区三区| 亚洲欧美乱色情图片| eeuss影院免费92242部| 51在线视频免费观看视频|