gpt4 book ai didi

java - 使用java从CLOB OUT参数从oracle中的存储过程获取值

转载 作者:行者123 更新时间:2023-12-01 10:50:57 27 4
gpt4 key购买 nike

我有 plsql/sql 存储过程,例如 myPackage.myProcedure。

我在 sqldeveloper 中获得了它的值(value)。

但是无论我做什么,当在 JAVA 中调用该过程时,我都无法获取 clob 值。

这是我的JAVA代码

Connectionmanager conn = new Connectionmanager();

OracleConnection conn1=null;
System.out.println("conn obj "+conn);
String docId = "xxxxxx";
String disptype ="xxxx";
String returnvalue="";
Clob myClob = conn.returnClob();
// CLOB clob = conn1.CreateClob();
String doctype = "xxxx";
// dbms_lob.createtemporary(OUTPUT_VALUE, true);
//CLOB myClob = null;
Connection con = conn.connectToDB();
//Connection cox = DriverManager.getConnection(docId)
try{
String stmt="BEGIN " + "dbms_lob.createtemporary(OUTPUT_VALUE, true); MYPACKAGE.MYPROCEDURE(?,?,?,?);" + "END;";
CallableStatement statement =con.prepareCall(stmt);
ResultSet rs=null;
statement.setString(1, docId);
statement.setString(2, disptype);
//call.setNull(1, Types.CLOB);
statement.registerOutParameter(3, Types.CLOB);

// here, the CLOB will be parsed into a string*
/*StringBuilder strOut = new StringBuilder();
String aux;

BufferedReader br = new BufferedReader(statement.getClob(3).getCharacterStream());
while ((aux=br.readLine())!=null)
strOut.append(aux);

// get xml text from function, one has been executed*
returnvalue = strOut.toString();*/
// statement.getClob(3);

//statement.setNull(3, Types.CLOB);
// statement.registerOutParameter(3, Types.ARRAY, typeTableName);
// statement.registerOutParameter(3,java.sql.Types.CLOB);

statement.setString(4, doctype);
rs= statement.executeQuery();

// System.out.println("out put is "+statement.getString(2));

}catch(Exception e)
{
System.out.println("e is "+e);
}

我已经评论了我尝试获取 clob 数据的所有方法。

我收到的错误是

java.sql.SQLException: ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275

有人可以帮助我吗?我什至尝试过这个查询

String stmt="DECLARE OUTPUT_VALUE CLOB; BEGIN " + "dbms_lob.createtemporary(OUTPUT_VALUE, true); PO_WF_PO_NOTIFICATION.GET_PO_LINES_DETAILS(?,?,?,?);" + "END;";

请帮助我,我真的需要这个

最佳答案

dbms_lob.createtemporary 应该位于程序包中。

public static void main(String[] args) throws SQLException, Exception {
Connection con = ConnectionDefinition.getOracleConnection(); //my oracle connection
CallableStatement cs = con.prepareCall("declare \n"
+ " procedure MYPROCEDURE(p1 varchar2,p2 varchar2,p3 out clob,p4 varchar2) is \n"
+ " begin \n"
+ " dbms_lob.createtemporary(p3, true); \n"
+ " dbms_lob.append(p3,p1||' - '||p2||' - '||p4);\n"
+ " end; \n"
+ "BEGIN\n"
+ " MYPROCEDURE(?,?,?,?);\n"
+ "END; \n"
+ " \n"
+ "");
cs.setString(1, "first param");
cs.setString(2, "secound param");
cs.registerOutParameter(3, Types.CLOB);
cs.setString(4, "four param");
cs.execute();
Clob cl = cs.getClob(3);
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
String line;
try {
br = new BufferedReader(new InputStreamReader(cl.getAsciiStream()));
while ((line = br.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
}
}
}
System.err.println(sb.toString());
}

关于java - 使用java从CLOB OUT参数从oracle中的存储过程获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33912920/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com