关于java调用oracle返回结果集的存储过程问题

carrysilence 2003-11-17 10:49:39
我已经写了一个可以返回游标的存储过程.

但是我无法调到结果,因为调用时,总是提示我列类型错误.

这是我的存储过程代码:

CREATE OR REPLACE PROCEDURE PROC_INT(
pr_c out pkg_test.t_cursor)
is
begin
open pr_c for select * from t_net;

END PROC_INT;

----
测试通过.

这是我的java代码:

CallableStatement toesUp = conn.prepareCall("{?=call proc_int}");
toesUp.registerOutParameter(1,Types.JAVA_OBJECT);
toesUp.execute();
ResultSet rs = (ResultSet) toesUp.getObject(1);

返回错误:
java.sql.SQLException: 无效的列类型
该错误指向 --> toesUp.registerOutParameter(1,Types.JAVA_OBJECT);

希望斑竹以及有这方面经验的各位高手能够帮我解决这个疑难.

谢谢览帖.

-----------
另,普通有返回参数的procdure调用都是成功的.
我不知道是不是 "jdbc版本" 的问题.

...全文
114 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yellowzhong 2003-12-28
  • 打赏
  • 举报
回复
ResultSet rs = (ResultSet) getResults.getObject(1);
这句好像有问题吧,
一般返回应该是用getCursor方法的
carrysilence 2003-11-19
  • 打赏
  • 举报
回复
这段代码很常见,我也是在这段代码上修改的。
不过,这段代码明显有错。
例如:getResults.execute();
我不知道去哪里得到这个方法。 ^_^
任怀林 2003-11-17
  • 打赏
  • 举报
回复
static void sendEarlyDeaths(PrintWriter out) {
Connection con = null;
CallableStatement toesUp = null;
try {
con = ConnectionPool.getConnection();
// PostgreSQL needs a transaction to do this...
con.setAutoCommit(false);
// Setup the call.
CallableStatement toesUp =
connection.prepareCall("{ ? = call proc_int() }");
toesUp.registerOutParameter(1, Types.OTHER);
getResults.execute();
ResultSet rs = (ResultSet) getResults.getObject(1);
while (rs.next()) {
String name = rs.getString(1);
int age = rs.getInt(2);
out.println(name + " was " + age + " years old.");
}
rs.close();
} catch (SQLException e) {
// We should protect these calls.
toesUp.close();
con.close();
}
}
carrysilence 2003-11-17
  • 打赏
  • 举报
回复
修正一下:

toesUp.registerOutParameter(1,Types.JAVA_OBJECT);

该句中各种Types我都一一试了一遍,1全部无效,只有在使用 REF 类型时,报2006冲突错误.

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧