简体   繁体   English

从 Java 通过数据库链接调用 PL-SQL 过程

[英]Calling PL-SQL Procedure over database link from Java

here my objective is to call a procedure over a database link in java.这里我的目标是通过 java 中的数据库链接调用一个过程。 procedure takes one input and has got cursor as an output.过程接受一个输入,并将光标作为输出。 to check if my code is working properly, I created dummy procedure in my database and tried executing.为了检查我的代码是否正常工作,我在我的数据库中创建了虚拟过程并尝试执行。 it is working, able to get cursor and play with it.它正在工作,能够获取光标并使用它。 however when i am calling some procedure over database link, getting error as但是,当我通过数据库链接调用某个过程时,出现错误

java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00201: identifier 'HR_CLICK_GET_EMP_DETAILS@IBSLUAT1.WORLD' must be declared

I had a call with developer who had created these procedure.我打电话给创建这些程序的开发人员。 according to him procedures exist at this end and access is already given to my user.根据他的程序存在于此端并且访问权限已经授予我的用户。

Now my questions and queries are现在我的问题和疑问是

  1. is there something different, i have to do while calling a procedure over database link(code is below)有什么不同吗,我必须在通过数据库链接调用过程时做(代码如下)

  2. what are the things i should be asking to sql developer.我应该向 sql 开发人员询问什么。 by the way database link is right.顺便说一下数据库链接是对的。

     String prc_name = "HR_CLICK_GET_CM_AND_ABOVE@IBSLUAT1.WORLD(?,?)"; String runSP = "{ call "+prc_name+" }"; String runSP1 = "{ call get_user_by_userId(?,?) }"; this one is working try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@xx.xx.xxx.xx:port:SERVICE", "username", "password"); // uat CallableStatement cs = conn.prepareCall(runSP); cs.setString(1, "705151"); cs.registerOutParameter(2, OracleTypes.CURSOR); cs.execute(); // get refcursor and convert it to ResultSet ResultSet resultSet = (ResultSet) cs.getObject(2); ResultSetMetaData rsmd = resultSet.getMetaData(); int columnCount = rsmd.getColumnCount(); System.out.println("Total Columns in ResultSet : "+columnCount); System.out.println("Now Analyzing column one by one:\\n\\n-----------------------------------------------"); for (int i = 1; i <= columnCount; i++ ) { String name = rsmd.getColumnName(i); System.out.println("Column No:"+i+">>>>>>>>"+name); } } catch(SQLException s) { s.printStackTrace(); } catch(ClassNotFoundException s) { s.printStackTrace(); }

thanks in advance提前致谢

Ashish阿西什

尝试使用拥有该过程的 Oracle 用户名作为前缀:

username.HR_CLICK_GET_EMP_DETAILS@IBSLUAT1.WORLD

Answer is "synonym".答案是“同义词”。

SQL Developer has created a synonym for HR_CLICK_GET_EMP_DETAILS as HR_CLICK_GET_EMP_DETAILS@IBSLUAT1.WORLD SQL Developer 为 HR_CLICK_GET_EMP_DETAILS 创建了同义词 HR_CLICK_GET_EMP_DETAILS@IBSLUAT1.WORLD

that is what he informed me, I could not quite wrap my head around that but able to hit the procedure.这就是他告诉我的,我无法完全理解这一点,但能够完成程序。

but now , able to get get the metadata of a result set but unable to traverse rows.但是现在,能够获取结果集的元数据但无法遍历行。

I'm getting an error:我收到一个错误:

java.sql.SQLException: ORA-24338: statement handle not executed java.sql.SQLException: ORA-24338: 语句句柄未执行

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)在 oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)在 oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)在 oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)在 oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:207)在 oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:207)
at oracle.jdbc.driver.T4CStatement.fetch(T4CStatement.java:1018)在 oracle.jdbc.driver.T4CStatement.fetch(T4CStatement.java:1018)
at oracle.jdbc.driver.OracleResultSetImpl.close_or_fetch_from_next(OracleResultSetImpl.java:291)在 oracle.jdbc.driver.OracleResultSetImpl.close_or_fetch_from_next(OracleResultSetImpl.java:291)
at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:213)在 oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:213)
at ashishtest.StoredProcedureCursor.main(StoredProcedureCursor.java:80)在 ashishtest.StoredProcedureCursor.main(StoredProcedureCursor.java:80)

I guess, new forum is required for this error.我想,这个错误需要新的论坛。

also I am not marking this as solved as not sure how solution works.我也没有将此标记为已解决,因为不确定解决方案是如何工作的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM