2

私はこのクラスを持っています

package com.middleware.jdbc.j2ee.websphere;
public class WS50NativeJDBCExtractorImpl implements NativeJDBCExtractorInf {
private Class webSphere5ConnectionClass;        
private Method webSphere5NativeConnectionMethod;    
private Class webSphere5StatementClass;   
private Method webSphere5NativeStatementMethod;

public WS50NativeJDBCExtractorImpl() throws Exception {
    try {
        this.webSphere5ConnectionClass = getClass().getClassLoader().loadClass("com.ibm.ws.rsadapter.jdbc.WSJdbcConnection");
        Class jdbcAdapterUtilClass = getClass().getClassLoader().loadClass("com.ibm.ws.rsadapter.jdbc.WSJdbcUtil");
        this.webSphere5NativeConnectionMethod = jdbcAdapterUtilClass.getMethod("getNativeConnection", new Class[] { this.webSphere5ConnectionClass });
        this.webSphere5StatementClass = getClass().getClassLoader().loadClass("com.ibm.ws.rsadapter.jdbc.WSJdbcStatement");
        this.webSphere5NativeStatementMethod = webSphere5StatementClass.getDeclaredMethod("getJDBCImplObject", null);
        this.webSphere5NativeStatementMethod.setAccessible(true);
    } catch (Exception ex) {
        e.printStackTrace();
    }
}
public Connection getConnection(Connection c) throws Exception {
    if (this.webSphere5ConnectionClass != null && this.webSphere5ConnectionClass.isAssignableFrom(c.getClass())) {
        try {
            return (Connection) this.webSphere5NativeConnectionMethod.invoke(null, new Object[] { c });
        } catch (Throwable e) {
            e.printStackTrace();
        }
    } else {
        return c;
    }
}
private Object primGetStatement(Statement stmt) throws Exception {
    if (this.webSphere5StatementClass != null && this.webSphere5StatementClass.isAssignableFrom(stmt.getClass())) {
        try {
            return this.webSphere5NativeStatementMethod.invoke(stmt, null);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    } else {
        return stmt;
    }
}
public CallableStatement getCallableStatement(CallableStatement cs) throws Exception {
    return (CallableStatement) primGetStatement(cs);
}}

WAS 8 インフォ センターで提案されているように WSCallHelper.jdbcCall を使用したいのですが、正しく取得できません。私は試した

Object st = WSCallHelper.jdbcCall(null, this.webSphere5StatementClass, "getJDBCImplObject", new Object[]{}, new Class[]{});

NOT_A_JDBC_OBJECT エラーが発生します。WSCallHelper を使用しなかったときは、

java.lang.ClassCastException: oracle.jdbc.driver.OracleCallableStatementWrapper incompatible with oracle.jdbc.OracleCallableStatement

私も使ってみました

CallableStatement cStmt = getCallableStatement(call);
if(stmt.isWrapperFor(OracleCallableStatement.class)){
    OracleCallableStatement ocs = (OracleCallableStatement) stmt;
}

(呼び出し変数にはSQLステートメントがあります)。stmt がラップされていないことを示しています。

上記のクラスを使用して、Oracle 9i データベースに接続しています。上記のコードに WSCallHelper.jdbcCall を使用する方法を知っている人はいますか? ありがとう。

4

3 に答える 3

1
if (con!=null){
    con = (Connection) WSCallHelper.getNativeConnection((WSJdbcConnection) con);
}

これは私にとってはうまくいきました。からネイティブ接続を取得し、com.ibm.websphere.rsadapter.WSCallHelperOracle 接続オブジェクトにキャストします。

于 2016-06-05T00:07:36.127 に答える
1

次のコードを使用して、oracle 接続を取得できます。

OracleConnection oracleConn=null;
if (conn!=null){
oracleConn= (OracleConnection) WSJdbcUtil.getNativeConnection((WSJdbcConnection) conn);
}

ここで、conn は、WAS データ ソースから取得した java.sql 接続です。これで、oracleConn オブジェクトを使用して目的の結果を得ることができます。

于 2012-10-15T09:59:35.277 に答える