c3p0 ResultSet.unwrap 抛出 AbstractMethodError

发布于 2024-08-16 23:26:55 字数 601 浏览 11 评论 0原文

我有一个 ResultSet 对象,需要将其转换为 OracleResultSet,以便我可以对其调用 getOPAQUE(String) 方法。我使用 c3p0 作为我的连接池。问题在于 c3p0 将 ResultSet 包装在 NewProxyResultSet 对象中。

这不应该是一个问题,因为我应该能够像这样在 ResultSet 上调用 unwrap:

rs.unwrap(OracleResultSet.class)

但是,这不起作用。它实际上抛出一个 AbstractMethodError:

java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyResultSet.unwrap(Ljava/lang/Class;)Ljava/lang/Object;

它包含堆栈跟踪,但它没有帮助,因为堆栈跟踪的顶行仅指向我调用 unwrap 方法的确切行。这似乎表明 NewProxyResultSet 本身没有实现 unwrap 。

这是怎么回事?如何获取 NewProxyResultSet 并从中获取 OracleResultSet?

I have a ResultSet object that I need to turn into an OracleResultSet so that I can call the getOPAQUE(String) method on it. I'm using c3p0 as my connection pool. The problem is that c3p0 wraps ResultSets in NewProxyResultSet objects.

This shouldn't be a problem because I should just be able to call unwrap on the ResultSet like this:

rs.unwrap(OracleResultSet.class)

However, that doesn't work. It actually throws an AbstractMethodError:

java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyResultSet.unwrap(Ljava/lang/Class;)Ljava/lang/Object;

It includes a stack trace, but it's not helpful because the top line of the stack trace just points to the exact line on which I call the unwrap method. That seems to indicate that NewProxyResultSet itself does not have unwrap implemented.

What's up with this? How can I take a NewProxyResultSet and get an OracleResultSet from it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森末i 2024-08-23 23:26:55

我想出了一个获得内在价值的方法!这是一个 hack,但它确实有效。如果有人知道一种更便携的方式来获取内在价值(比如使展开方法起作用),那么我很乐意这样做。

但是,事实证明 NewProxyResultSet 的“内部”变量被声明为受保护的。所以我只是在与 NewProxyResultSet 相同的包中创建一个类,并使用它来获取内部值,如下所示:

package com.mchange.v2.c3p0.impl;

import java.sql.ResultSet;

/**
 * This is a sneaky way to get at the inner ResultSet of NewProxyResultSet. It marks the     variable as protected,
 * so here I just make a class in the same package and get the value out. 
 *
 */
public class C3P0ResultSetPeeker
{
public static ResultSet getInnerFrom(NewProxyResultSet rs) {
    return rs.inner;
}
}

I figured out a way to get the inner value! It's a hack, but it works. If anyone knows a more portable way of getting the inner value (like making the unwrap method work) then I'd love to do that instead.

But, it turns out that the "inner" variable of the NewProxyResultSet is declared protected. So I just make a class in the same package as NewProxyResultSet and use it to get the inner value like so:

package com.mchange.v2.c3p0.impl;

import java.sql.ResultSet;

/**
 * This is a sneaky way to get at the inner ResultSet of NewProxyResultSet. It marks the     variable as protected,
 * so here I just make a class in the same package and get the value out. 
 *
 */
public class C3P0ResultSetPeeker
{
public static ResultSet getInnerFrom(NewProxyResultSet rs) {
    return rs.inner;
}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文