详解java调用存储过程并封装成map
本文代码中注释写的比较清楚不在单独说明,希望能帮助到大家,
实例代码:
public List> doCallProcedure(String procedureString,String[] parameters) throws PersistentDataOperationException { if (!isReady ()) { throw new PersistentDataOperationException( "DAO is not ready."); } ResultSet rs = null; List> list = new ArrayList>(); try { Connection con=session.connection(); String procedure = "{call "+procedureString+ "(?,?,?) }"; //拼装调用存储过程字符串 CallableStatement cstmt = con.prepareCall (procedure ); //调用存储过程 cstmt.setString (1,parameters [0 ]); //设置入参 cstmt.setInt (2, Integer. parseInt( parameters[ 1])) ;//设置入参 cstmt.registerOutParameter (3, oracle.jdbc.OracleTypes.CURSOR ); //设置出参 cstmt.execute (); //执行提交 rs = (ResultSet ) cstmt.getObject (3 ); //获取出参,3为参数顺序数 ResultSetMetaData rsm =rs.getMetaData (); //获得列集 Map map= null; int col = rsm.getColumnCount (); //获得列的个数 String colName [] = new String[ col] ;//列名集合 for (int i = 0; i (); for (int j = 0; j
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!