我在weblogic中遇到错误:
java.lang.ClassCastException:weblogic.jdbc.wrapper.Array_oracle_sql_ARRAY无法转发到weblogic.jdbc.wrapper.CallableStatement_oracle_jdbc_driver_OracleCallableStatementWrapper.getARRAY(未知来源)
的oracle.sql.ARRAY
代码:
public String[] methodName(String[] P1,String P2,String P3,String P4, String P5,int Sessioninfo)
{
Connection conn = null;
CallableStatement cstmt = null;
ResultSet rs = null;
String[] returnArray = null;
try {
ds=getDataSource(Sessioninfo);
conn = ds.getConnection();
conn = new CommonsDbcpNativeJdbcExtractor().getNativeConnection(conn);
conn.setAutoCommit(false);
ArrayDescriptor oracleVarchar2Collection =
ArrayDescriptor.createDescriptor("VARRAY_PARTS",conn);
ARRAY sqlNos = new ARRAY(oracleVarchar2Collection, conn, P1);
cstmt =conn.prepareCall("{call Procedure1(?,?,?,?,?,?)}");
cstmt.setObject(1, sqlNos);
cstmt.setString(2, P2);
cstmt.setString(3, WebpartsUtility.convertSQLStringIN(P3,","));
cstmt.setString(4, WebpartsUtility.convertSQLStringIN(P4,","));
cstmt.setString(5,P5);
cstmt.registerOutParameter(6,OracleTypes.ARRAY, "VARRAY_PARTS");
cstmt.setFetchSize(2500);
cstmt.execute();
ARRAY mainArray = ((OracleCallableStatement)cstmt).getARRAY(6);
returnArray = (String[]) mainArray.getArray();
} catch (SQLException ex) {
logger.fatalMsg("Sql Exception Occured :: "+ex.getMessage(),ex);
} catch (Exception ex) {
logger.fatalMsg("Exception Occured :: "+ex.getMessage(),ex);
} finally {
try {
if (cstmt != null) {
cstmt.close();
cstmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
if (ds != null) {
ds = null;
}
} catch (SQLException ex) {
logger.fatalMsg("Sql Exception Occured :: "+ex.getMessage(),ex);
} catch (Exception ex) {
logger.fatalMsg("Exception Occured :: "+ex.getMessage(),ex);
}
}
return returnArray;
}
答案 0 :(得分:1)
有时连接是作为本机连接的包装返回的,您需要打开它:
conn = new CommonsDbcpNativeJdbcExtractor().getNativeConnection(conn);
OracleConnection oConn;
if ( conn.isWrapperFor( OracleConnection.class ) )
{
oConn = (OracleConnection) conn.unwrap( OracleConnection.class );
}
else
{
oConn = (OracleConnection) conn;
}
或者,根据this answer,您可以获得基础可调用语句(而不是包装语句):
OracleCallableStatement cstmt
= (OracleCallableStatement) conn.prepareCall("{call Procedure1(?,?,?,?,?,?)}")
.getUnderlyingStatement();
另一个可能的解决方案是不使用中间变量,只做:
returnArray = (String[]) ((OracleCallableStatement)cstmt).getARRAY(6).getArray();
<强>更新强>:
根据this answer您还可以尝试:
ARRAY mainArray = (ARRAY) ((weblogic.jdbc.wrapper.Array) (callableStmt).getObject(3))
.unwrap(ARRAY.class);
答案 1 :(得分:1)
问题得到解决,添加以下代码:
class SearchBarContainer extends Component {
selectPost = (post) => {
this.props.history.push('/product/foo');
this.props.actions.selectPost(post)
}
render() {
return (
<div>
<div className="center-xs">
<p>To get started, type in some keywords below</p>
</div>
<SearchBar onTermChange={this.props.actions.loadPosts} onNull={this.props.actions.nullPosts}/>
<PostList posts={this.props.posts} isFetching={this.props.isFetching} onClick={this.selectPost}/>
</div>
);
}
}
export default withRouter(SearchBarContainer);
您可以查看以下链接:http://adfpractice-fedor.blogspot.com/2011/09/weblogic-wrapping-data-types.html
答案 2 :(得分:0)
对数据源进行简单的参数更改即可使其正常工作。
转到数据源->选择数据源->配置->连接池->高级,然后取消选中“包装数据类型”。
这应该可以解决问题。