c3p0 ResultSet.unwrap throws an AbstractMethodError

筅森魡賤 提交于 2019-12-11 01:46:18

问题


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?


回答1:


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;
}
}


来源:https://stackoverflow.com/questions/1971617/c3p0-resultset-unwrap-throws-an-abstractmethoderror

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!