您的位置:首页 > 编程语言 > Java开发

[置顶] Debugging PL-SQL calls from Java Session Using Eclipse and SQL Developer

2016-07-14 01:44 656 查看
1 问题背景

最近在做自己的开源项目,使用jdbc去调用oracle的一个分页存储过程,如下图,1出执行的代码始终得不到数据(rs.next=false).几经折腾,在eclipse中调试java代码,没有找到原因.

在pl/sql developer中调试存储过程,也没有找到原因,由于中pl/sql developer中调试存储过程需要手动给参数赋值,结果每次cursor变量都有值,但就是java中调用没有值.后来很想看到在调试java代码中的存储过程时,能否同时进入pl/sql developer中,调试存储过程sql代码,等存储过程sql代码调试完,再返回java中,接着调试java代码.带着疑问,在google上不断搜索.以下就是解决方案.



2 详细步骤

a)O[b]pen the package in Oracle SQL
developer. Right click both body and spec and compile for DEBUG
[/b]

[b]


[/b]

Note: If the package is using some
user defined type objects as input or output then compile those objects for DEBUG.


b)Go to tools -> Preferences -> Debugger. 
Select the option Prompt for Debugger host for Database Debugging.







c)[b]Right
click the DB connection and start the remote debug session
[/b]

[b]

[/b]

   It will open the Listen for JPDA dialog. In Local address enter the ip address of the machine and hit OK.





  This will start the debug listener as follows.



d)Now in the java program calling the PL/SQL package before the actual PL/SQL call enter the following code

[b]  //For debugging only[/b]
[b]        CallableStatement debugStatement = getCallableStatement("begin DBMS_DEBUG_JDWP.CONNECT_TCP( '<ipaddress provided above>', 4000 ); end;");
//Note         the ipaddress and port – Same as the values provided in the previous dialog.
[/b]
[b]        debugStatement.execute();[/b]
 // execute the actual PL/SQL call
[b]     statement.execute();[/b]
[b]  In my case :[/b]
[b]  

[/b]
[b]e)[/b]Now open the PL/SQL package and put a break point where you want to debug
something.





     When
you invoke the  PL/SQL program from Java





   

It will stop at the first break point in PL/SQL as follows. Note that you can see the values passed by Java in the user defined             object. The objects appearing
as opaque needs to be recompiled for debug. Now you can debug through each line in PL/SQL much   like java code



 Enjoy
– Happy PL/SQL Debugging. Let me know if there is any question.

3
参考资料

https://blogs.oracle.com/shay/entry/debugging_java_and_plsql_toget(flash视频,演示jdeveloper中如何实现)

http://sanat-pattanaik-debug.blogspot.hk/2011/01/debugging-pl-sql-calls-from-java.html (主要参考该资料,请自备梯子)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: