jdbc接続を計測しようとしています。私はこのトピックに関するいくつかの同様の質問があることを知っています。
私はすべてを試みましたが、これまでのところ私の問題を解決するための方法を見つけることができませんでした。 はまた、結果なしで、この質問への回答を試してみました:私は私のcontext.xmlでOracle接続プールを定義し Apache Commons DBCP connection object problem, Thread: ClassCastException in org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
私はここでのTomcat 7とJava 7で働いています:
<Resource name="jdbc/myDS"
type="javax.sql.DataSource"
auth="Container"
maxActive="350"
maxIdle="50"
minIdle="10"
maxWait="10000"
username="user_own"
password="mypassw"
accessToUnderlyingConnectionAllowed="true"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@192.168.110.173:1521/orcl" />
マイ計測コード:
private static void initInstrumentation(Connection con, final String usuario, final String modulo, final String accion) throws Exception {
if (IncVariablesPlx.getParameter("instrumentation.active").equals("1")) {
try {
OracleConnection oracleConnection = null;
//This is where I try to get the oracle connection, but no succeed
if (con != null) {
if (con instanceof OracleConnection) {//NEVER COME IN HERE
oracleConnection = (OracleConnection) con;
} else if (con.isWrapperFor(OracleConnection.class)) {//NEVER COME IN HERE
oracleConnection = con.unwrap(OracleConnection.class);
} else{
//NO ORACLECONNECTION NO isWrapperFor -> ALWAYS ENDS HERE!!!
//oracleConnection = (OracleConnection) ((DelegatingConnection) con).getDelegate();
oracleConnection = (OracleConnection) new DelegatingConnection(con).getInnermostDelegate();
}
}
if (oracleConnection != null) {
String[] metrics = new String[OracleConnection.END_TO_END_STATE_INDEX_MAX];
metrics[OracleConnection.END_TO_END_MODULE_INDEX] = modulo;
metrics[OracleConnection.END_TO_END_ACTION_INDEX] = "Inicio: " + accion;
metrics[OracleConnection.END_TO_END_CLIENTID_INDEX] = usuario;
oracleConnection.setEndToEndMetrics(metrics, (short) 0);
}
} catch (Exception e) {
throw new Exception("Error initInstrumentation " + e);
}
}
}
マイオープン接続方法:
private static Connection genericOpenConnection() throws Exception {
Connection con = null;
try {
DataSource dataSource = (DataSource) new InitialContext().lookup(IncFuncionesPlx.cStrPlx(IncVariablesPlx.getParameter("dataSourceJndiName")));
con = dataSource.getConnection();
con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
} catch (Exception e) {
Error.escribeLog("Error : " + e.getMessage());
throw new SQLException(e.getMessage());
}
return con;
}
openConnectionとinitInstrumentationを呼び出した後、次の例外が発生して接続をOracle接続にキャストしようとしています。どのようにこれを行うための任意のアイデア?私は何が間違っていますか? ありがとうございます。
とjava.lang.ClassCastException:org.apache.tomcat.dbcp.dbcp.PoolingDataSource $ PoolGuardConnectionWrapperはのoracle.jdbc.OracleConnection
下記のように接続が今取得されている、私が読んで、すべてのものを試してみた、含まあなたはそれが重複していると言った質問... – elcadro
'getInnermostDelegate'を呼び出そうとしましたか? –
うん、それもやってみた... – elcadro