`
longzhun
  • 浏览: 371970 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JDBC调用函数和存储过程

阅读更多

JDBC调用存储过程

1

Connection conn = null;

CallableStatement cstmt=null;  

PreparedStatement ps = null;

Conn=oracleJdbcTemplate.getDataSource().getConnection();

cstmt = conn.prepareCall("{ call SYN_CONTROL_SERVER.PRC_UPDATE_SENDMESSAGE_LIST (?,?,?)}");

//设置输入参数

cstmt.setString(1, entPc);

cstmt.setString(2, codeType);

cstmt.setString(3, msg);

cstmt.execute();

2

Object obj = oracleJdbcTemplate.execute(new ConnectionCallback() {

public Object doInConnection(Connection conn) throws SQLException, DataAccessException {

              conn.setAutoCommit(true);

              CallableStatement cstmt = conn.prepareCall("{call SYN_CONTROL_SERVER.PRC_MAIN(?)}");

              //设置输出参数

              cstmt.registerOutParameter(1, Types.VARCHAR);

              cstmt.execute();

              String out = cstmt.getString(1);

              cstmt.close();

              conn.setAutoCommit(false);

              return out;

           }

       });

JDBC调用函数(oracle函数必要要有返回值)

        Object obj =

             oracleJdbcTemplate.execute(new ConnectionCallback(){

               public Object doInConnection(Connection conn) throws SQLException, DataAccessException{

                conn.setAutoCommit(true);

                CallableStatement cstmt = conn.prepareCall("{?=call GET_IDECL_SERVER.FC_GET_MAX (?,?)}");

                cstmt.setString(2, ptype);

                cstmt.setString(3, prefix);

                cstmt.registerOutParameter(1, Types.VARCHAR);

                cstmt.execute();

                String out = cstmt.getString(1);

                cstmt.close();

                conn.setAutoCommit(false);

                return out;

               }

              });

分享到:
评论
2 楼 longzhun 2011-10-17  
出差沈阳市委,一直没上网,今天才看到,不好意思,存储过程又函数的话,调用是一样的
1 楼 piaoxue_x 2011-10-12  
如果存储过程中还有函数,在java程序中该如何处理。。。。。
和调用平常的存储过程一样吗?

相关推荐

Global site tag (gtag.js) - Google Analytics