《callablestatement使用示例》由会员分享,可在线阅读,更多相关《callablestatement使用示例(4页珍藏版)》请在金锄头文库上搜索。
1、Callablestatement使用示例:/ 第一个java调过程的例子,没有参数的过程public void callProWithoutPram()try CallableStatement casm = conn.prepareCall(call Test);casm.execute(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace(); / 第二个java调过程的例子,有 IN 参数的过程public void callProWithPram()try CallableStatem
2、ent casm = conn.prepareCall(call Test(?,?,?,?,?);casm.setInt(1, 4);casm.setInt(2, 1);casm.setString(3, 绿灯侠);casm.setString(4, 3D电影);casm.setDouble(5, 40.56);casm.executeUpdate(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace(); / 第二个java调过程的例子,有 IN 参数的带包名的过程public void ca
3、llProWithPramPack()try CallableStatement casm = conn.prepareCall(call product_package.update_product_price(?);casm.setInt(1, 2);casm.executeUpdate(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace(); / 第三个java调过程的例子,有 OUT 参数的过程public void callProWithPramOut()try CallableSt
4、atement casm = conn.prepareCall(call Test(?);casm.registerOutParameter(1, java.sql.Types.INTEGER);casm.execute();int num = casm.getInt(1);System.out.println(out parm :+num);casm.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace(); / 第四个java调函数的例子,无参数,返回游标对象public voi
5、d callFunWithoutPram()try CallableStatement casm = conn.prepareCall(?=call product_package.get_products_ref_cursor);casm.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);casm.execute(); rs = (ResultSet) casm.getObject(1); while (rs.next() System.out.println(t + rs.getString(1) + t + rs.getString(2) + t + rs.getString(3) + t); casm.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();