0
public String getObjectDetails(String buffer) {
        dbcon con = new dbcon();        
        ResultSet rs = null;
        String name_msg=null;
        String type_msg=null;
        int type_code=0;
        int name_code=0;
        try {
            rs = con.dbstate().createStatement().executeQuery("SELECT pkg_test1.get_object_type('"+buffer+"',"+type_code+",'"+type_msg+"'),pkg_test1.get_object_name('"+buffer+"',"+name_code+",'"+name_msg+"') from dual");
            if (rs.next()) {
                return rs.getString(1) + "," + rs.getString(2);
            }
        } catch (SQLException ex) {
            Logger.getLogger(username.class.getName()).log(Level.SEVERE, null, ex);
        }
        return "";
    }

而且,我正在尝试从PKG_TEST1包内声明的这两个函数中获取信息

FUNCTION get_object_type(i_buffer IN VARCHAR2, o_errcode OUT NUMBER,
                           o_errmsg OUT VARCHAR2) RETURN VARCHAR2;

  FUNCTION get_object_name(i_buffer IN VARCHAR2, o_errcode OUT NUMBER,
                           o_errmsg OUT VARCHAR2) RETURN VARCHAR2;

但是,我收到错误

java.sql.SQLException: ORA-06572: Function GET_OBJECT_NAME has out arguments

请帮我解决这个问题。

4

2 回答 2

1

尝试这个

    CallableStatement c = conn.prepareCall("{? = call get_object_type(?, ?)}");
    c.registerOutParameter(1, Types.VARCHAR);
    c.registerOutParameter(3, Types.VARCHAR);
    c.setString(2, buffer);
    c.execute();
    String res = c.getString(1);
    String err = c.getString(3);
于 2013-09-17T06:09:12.780 回答
0

这对我有用,感谢@home 向我推荐了良好的链接。

String call = "{ ? = call pkg_test1.get_object_type(?,?,?)}";
CallableStatement cstmt = con.dbstate().prepareCall(call);
 cstmt.registerOutParameter(1, oracle.jdbc.OracleTypes.VARCHAR);
cstmt.setString(2, buffer);
cstmt.registerOutParameter(3, oracle.jdbc.OracleTypes.NUMBER);
cstmt.registerOutParameter(4, oracle.jdbc.OracleTypes.VARCHAR);
cstmt.executeQuery();
String type = cstmt.getString(1);

在这里很好地解释:如何调用 Stred 过程和函数

于 2013-09-17T06:16:24.650 回答