Oracle JDBC 可调用语句和 getMetadata 计数

Oracle JDBC callable statement and getMetadata count

假设我有一个 pl/sql 如下所示:

  final Connection c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "manager");
    String plsql = "" +
    " declare " +  
    "    p_id varchar2(20) := null; " +
    "    l_rc sys_refcursor;" +
    " begin " +
    "    p_id := ?; " +
    "    ? := 'input parameter was = ' || p_id;" +
    "    open l_rc for " +
    "        select 1a id, 'hello' name from dual " +
    "        union " +
    "        select 2a, 'peter' from dual; " +
    "    ? := l_rc;" +
    " end;";

    CallableStatement cs = c.prepareCall(plsql);
    cs.setString(1, "12345");
    cs.registerOutParameter(2, Types.VARCHAR);
    cs.registerOutParameter(3, OracleTypes.CURSOR);

    cs.execute();

一切都很好,但我怎样才能从中获得 metadat.getColumnCount()?

我想达到什么目的? 而不是:

 ResultSet cursorResultSet = (ResultSet) cs.getObject(3);
        while (cursorResultSet.next ())
        {
            System.out.println (cursorResultSet.getString(1) + " " + cursorResultSet.getString(2));
        } 

我想查找元数据计数并在循环中打印一条记录的所有值,例如:

//伪代码

int x = callablestatement.metadata.count();
String myRecord='';
while (cursorResultSet.next ()){
        for(int i=1; i<=x; i++){
          myRecord= myRecord+ " " + cursorResultSet.getString(i);
                               }
                               }

获取结果集中的列数,需要使用

cursorResultSet.getMetaData().getColumnCount()