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

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

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

    waterye

    JDBC call Stored Procedure

    現在的ORM(如Hibernate)性能一直不是很理想, 一些大型的J2EE項目還是以JDBC為主, 但一直對SP(Stored Procedure)有抵制情緒, 搞得SQL滿天飛, 因最近幾周用PL/SQL弄歷史數據遷移的問題, 順便整理一下JDBC調用SP.

    The simple SQL statement will always execute faster than calling a stored procedure. Why? Because with the stored procedure, you not only have the time needed to execute the SQL statement but also the time needed to deal with the overhead of the procedure call itself.

    Stored procedures do have their uses. If you have a complex task that requires several SQL statements to complete,
    and you encapsulate those SQL statements into a stored procedure that you then call only once, you'll get better performance than if you executed each SQL statement separately from your program. This performance gain is the result of your program not having to move all the related data back and forth over the network, which is often the slowest part of the data manipulation process. This is how stored procedures are supposed to be used with Oracle -- not as a substitute for SQL, but as a means to perform work where it can be done most efficiently.

    Function and Procedure
    The difference between a procedure and function is that a function returns a value, so it can be used as an evaluated item in an expression. A procedure does not return a value. However, both functions and procedures can have OUT or IN OUT variables that return values.

    CREATE [OR_REPLACE] FUNCTION function_name
     [(parameter_declaration [, parameter_declaration]...)]
    RETURN datatype
     [AUTHID {CURRENT_USER | DEFINER}]
     [PARALLEL_ENABLE] [DETERMINISTIC] {IS | AS}
     ......
    BEGIN statement [statement]...
     [EXCEPTION exception_handler [exception_handler]...]
    END [function_name];

    [CREATE [OR_REPLACE]] PROCEDURE procedure_name
     [(parameter_declaration [, parameter_declaration]...)]
     [AUTHID {CURRENT_USER | DEFINER}] {IS | AS}
     ......
    BEGIN statement [statement]...
     [EXCEPTION exception_handler [exception_handler]...]
    END [procedure_name];

    Package
    A package is a schema object that groups logically related PL/SQL types, variables, and subprograms.
    Packages usually have two parts, a specification and a body; sometimes the body is unnecessary.

    package_spec ::=
    CREATE [OR_REPLACE] PACKAGE [schema_name .] package_name
     [AUTHID {CURRENT_USER | DEFINER}] {IS | AS}
     ......
    END [package_name];

    package_body ::=
    CREATE [OR_REPLACE] PACKAGE_BODY [schema_name .] package_name
     {IS | AS} [PRAGMA SERIALLY_REUSABLE;]
     ......
     [BEGIN statement [statement]...]
    END [package_name];

    IN, OUT, IN OUT
    An IN parameter passes values to the subprogram being called.
    An OUT parameter returns values to the caller of the subprogram.
    An IN OUT parameter passes initial values to the subprogram being called, and returns updated values to the caller.

    JDBC call Stored Procedure

    CallableStatement cstmt = conn.prepareCall("{ ? = call md5( ? ) }");
    // CallableStatement cstmt = conn.prepareCall("begin ? := md5( ? ); end;"); // oracle syntax
    cstmt.registerOutParameter(1, Types.VARCHAR); // set out parameters
    cstmt.setString(2"idea"); // set in parameters
    cstmt.execute();
    String md5Str 
    = cstmt.getString(1); // Getting OUT Parameter Values
    cstmt.close();


    參考:
    1. Java Programming with Oracle JDBC
    2. PL/SQL User's Guide and Reference

    BTW: 有人在項目中使用oracle的Object-Relational SQL嗎? 性能如何? 開發效率?

    posted on 2006-01-13 16:59 waterye 閱讀(5027) 評論(0)  編輯  收藏 所屬分類: Java

    主站蜘蛛池模板: 在线观看免费无码专区| 中国亚洲呦女专区| 国产免费MV大全视频网站| 热久久精品免费视频| 国产亚洲精品VA片在线播放| 国产92成人精品视频免费| 亚洲色成人网一二三区| 91短视频免费在线观看| 99亚偷拍自图区亚洲| 热久久精品免费视频| 丰满妇女做a级毛片免费观看| 中文字幕在亚洲第一在线| 91精品全国免费观看青青| 久久久久亚洲AV无码专区首| 最近免费中文字幕mv电影| 国产色在线|亚洲| 日韩免费高清视频网站| 日韩精品视频在线观看免费| 亚洲国产精品无码久久久蜜芽| 精品国产污污免费网站| 亚洲一级毛片视频| 四虎永久免费观看| 你是我的城池营垒免费看| 亚洲综合图片小说区热久久| 成人a视频片在线观看免费| 羞羞视频在线观看免费| 国产成人亚洲综合无码精品 | 最近在线2018视频免费观看| 亚洲一区无码中文字幕乱码| 国产一区二区免费在线| 中文字幕免费播放| 亚洲久悠悠色悠在线播放| 亚洲日本va午夜中文字幕久久| 日韩精品内射视频免费观看| 亚洲 欧洲 日韩 综合在线| 国产成人亚洲综合无码| 久久精品国产免费观看三人同眠| 久久精品国产亚洲AV未满十八| 久久亚洲国产精品一区二区| 无码视频免费一区二三区| 国产一级高青免费|