我有這個類爲WSCallHelper.jdbcCall實施是8
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);
}}
我想用WSCallHelper.jdbcCall作爲爲8信息中心建議,但我不能夠得到它正確的。我試過
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來獲取上面的代碼?謝謝。
我認爲'WSJdbcUtil'中的方法已被棄用。我正在嘗試'com.ibm.websphere.rsadapter.WSCallHelper.getNativeConnection()'。 – FrustratedWithFormsDesigner 2014-01-14 23:18:58