2012-03-15 2 views
2

8は、私はこのクラスWSCallHelper.jdbcCallの実装は

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を使用していない場合は、私はまた

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

(コール変数を持つSQL文)を使用しようとした

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

を取得しています。それはstmtがラップされていないと言います。

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

答えて

1

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

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

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

+0

私は 'WSJdbcUtil'のメソッドは廃止予定だと思います。私は 'com.ibm.websphere.rsadapter.WSCallHelper.getNativeConnection()'を試しています。 – FrustratedWithFormsDesigner

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

これは私に役立ちました。 com.ibm.websphere.rsadapter.WSCallHelperからネイティブ接続を取得し、Oracle接続オブジェクトにキャストします。