posts - 431,  comments - 344,  trackbacks - 0

          內容或簡介:
          /**
          調用數據庫里的一個函數
          一個函數本質上一個返回一個結果的存儲過程,這個例子示范了怎么調用有in、out和in/out參數的函數
          ***********************************/
          CallableStatement cs;
          try {
          // 調用一個沒有參數的函數; 函數返回 a VARCHAR
          // 預處理callable語句 
              cs = connection.prepareCall("{? = call myfunc}");

          // 注冊返回值類型
              cs.registerOutParameter(1, i);

          // Execute and retrieve the returned value
              cs.execute();
              String retValue = cs.getString(1);

          // 調用有一個in參數的函數; the function returns a VARCHAR
              cs = connection.prepareCall("{? = call myfuncin(?)}");

          // Register the type of the return value
              cs.registerOutParameter(1, Types.VARCHAR);

          // Set the value for the IN parameter
              cs.setString(2, "a string");

          // Execute and retrieve the returned value
              cs.execute();
              retValue = cs.getString(1);

          // 調用有一個out參數的函數; the function returns a VARCHAR
              cs = connection.prepareCall("{? = call myfuncout(?)}");

          // Register the types of the return value and OUT parameter
              cs.registerOutParameter(1, Types.VARCHAR);
              cs.registerOutParameter(2, Types.VARCHAR);

          // Execute and retrieve the returned values
              cs.execute();
              retValue = cs.getString(1);           // return value
              String outParam = cs.getString(2);    // OUT parameter

          // 調用有一個in/out參數的函數; the function returns a VARCHAR
              cs = connection.prepareCall("{? = call myfuncinout(?)}");

          // Register the types of the return value and OUT parameter
              cs.registerOutParameter(1, Types.VARCHAR);
              cs.registerOutParameter(2, Types.VARCHAR);

          // Set the value for the IN/OUT parameter
              cs.setString(2, "a string");

          // Execute and retrieve the returned values
              cs.execute();
              retValue = cs.getString(1);           // return value
              outParam = cs.getString(2);           // IN/OUT parameter
          } catch (SQLException e) {
          }

          posted on 2009-03-11 21:05 周銳 閱讀(264) 評論(0)  編輯  收藏 所屬分類: Oracle
          主站蜘蛛池模板: 南安市| 即墨市| 项城市| 白朗县| 通道| 土默特左旗| 边坝县| 新竹县| 河南省| 葫芦岛市| 无极县| 祁东县| 神农架林区| 万源市| 揭阳市| 栾川县| 于都县| 和林格尔县| 连城县| 怀柔区| 雅江县| 滁州市| 永昌县| 广州市| 平昌县| 电白县| 高碑店市| 陵川县| 龙州县| 靖江市| 札达县| 榆社县| 镇康县| 伊通| 东山县| 嵩明县| 化隆| 墨江| 集贤县| 绥宁县| 大渡口区|