<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 閱讀(5026) 評論(0)  編輯  收藏 所屬分類: Java

    主站蜘蛛池模板: 久久青草91免费观看| 无人视频在线观看免费播放影院| h视频在线免费看| 亚洲av无码无在线观看红杏| aa午夜免费剧场| 亚洲国产精品一区第二页 | 妞干网在线免费视频| 久久伊人久久亚洲综合| 在线毛片片免费观看| 亚洲国产成人私人影院| 99热在线精品免费播放6| 亚洲精品午夜在线观看| 亚洲欧洲免费视频| 亚洲国产精品成人久久久| 91在线视频免费播放| 亚洲欧美日韩中文无线码| 四虎永久在线精品视频免费观看| 亚洲AV无码精品色午夜在线观看| 亚洲毛片免费观看| 国产精品视频永久免费播放| 日本亚洲精品色婷婷在线影院| 大地资源在线资源免费观看| 亚洲成在人天堂一区二区| 100000免费啪啪18免进| 亚洲精品伦理熟女国产一区二区 | 在线免费视频你懂的| 亚洲综合伊人久久大杳蕉| 国色精品va在线观看免费视频 | 亚洲一区二区三区香蕉| 精品四虎免费观看国产高清午夜| 日本不卡高清中文字幕免费| 青娱乐在线视频免费观看| 91麻豆国产自产在线观看亚洲| 一本色道久久88—综合亚洲精品 | 亚洲午夜无码AV毛片久久| 日韩精品在线免费观看| 精品亚洲成在人线AV无码| 精品国产麻豆免费网站| a级片在线免费看| 亚洲人成网站看在线播放| 中文字幕亚洲天堂|