有没有办法找出数据库游标是否在Java中打开? [英] Is there a way to find out a database cursor is open or not in Java?

查看:456
本文介绍了有没有办法找出数据库游标是否在Java中打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JDBC中是否有办法找出JAVA中是否打开游标。
我们在尝试访问未打开的游标时遇到异常。
java.sql.SQLException:光标已关闭。

Is there a way in JDBC to find out the cursor opened or not in JAVA. We are getting an exception when tried to access an un opened cursor. java.sql.SQLException: Cursor is closed.

以下是正在发生的事情。

Here is what is happening.

存储过程就是这样设计的。 proc返回游标和其他几列。对于某些情况,DB人员不会打开游标并仅返回游标外的其他剩余列。因此,当Java代码尝试获取游标时,它会抛出此异常。我知道,我可以捕获异常并继续进行其余的列。但我想知道是否有不同的(可能更好)的方法来处理这个问题?
或者只需要在存储过程中打开游标,即使游标中没有任何内容可以返回?

The Stored proc is designed this way. the proc returns the cursor and a couple of other columns. For some conditions, the DB guy is not opening the cursor and returns only the other remaining column outside of the cursor. So when the Java code tries to get cursor, it throws this exception. I know, I can catch the exception and proceed further with the remaining columns. But I was wondering is there a different (may be better) way to handle this? Or just need to open the cursor in the stored proc, even if there is nothing to return as part of the cursor?

推荐答案

也许可以更改存储过程以返回一个值,指示游标是否打开。以下内容可能有用:

Perhaps the stored proc could be changed to return a value indicating if the cursor is open. Something like the following might be useful:

TYPE tCursor IS REF CURSOR;

PROCEDURE A_PROC(returned_cursor    OUT tCursor,
                 bCursor_is_open    OUT BOOLEAN,
                 aNother_value      OUT NUMBER,
                 yet_another_value  OUT NUMBER);

如果打开游标,程序应将bCursor_is_open设置为TRUE,否则如果游标未打开则设置为FALSE 。

The procedure should set bCursor_is_open to TRUE if it opens the cursor, or FALSE if the cursor is not opened.

这篇关于有没有办法找出数据库游标是否在Java中打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆