hk2000c技術專欄

          技術源于哲學,哲學來源于生活 關心生活,關注健康,關心他人

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            111 隨筆 :: 1 文章 :: 28 評論 :: 0 Trackbacks

          內容或簡介:
          /**
          調用數(shù)據(jù)庫里的一個函數(shù)
          一個函數(shù)本質上一個返回一個結果的存儲過程,這個例子示范了怎么調用有in、out和in/out參數(shù)的函數(shù)
          ***********************************/
          CallableStatement cs;
          try {
          // 調用一個沒有參數(shù)的函數(shù); 函數(shù)返回 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參數(shù)的函數(shù); 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參數(shù)的函數(shù); 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參數(shù)的函數(shù); 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 2007-11-16 17:18 hk2000c 閱讀(301) 評論(0)  編輯  收藏 所屬分類: Oracle存儲過程

          只有注冊用戶登錄后才能發(fā)表評論。


          網站導航:
           
          主站蜘蛛池模板: 灵璧县| 呼玛县| 元阳县| 昌宁县| 巢湖市| 万安县| 江孜县| 西青区| 五寨县| 潼关县| 兰州市| 萍乡市| 宽城| 新兴县| 诏安县| 横山县| 邵武市| 仁怀市| 金坛市| 龙州县| 藁城市| 静安区| 万山特区| 舞钢市| 张掖市| 吉木乃县| 梧州市| 永宁县| 乌拉特前旗| 随州市| 蓬溪县| 钟祥市| 富民县| 江安县| 临洮县| 咸丰县| 鹤岗市| 本溪市| 师宗县| 昌邑市| 临潭县|