wtorek, kwietnia 30, 2013

How get real JDBC connection in BW Java

com.tibco.plugin.java.JavaConnectionAccessor ac = (com.tibco.plugin.java.JavaConnectionAccessor) conn;
java.sql.Connection wrappedConn = ac.getDBConnection();
java.sql.PreparedStatement ps = null;
java.sql.Clob val_binary = null;
try {
    java.lang.reflect.Field connField = null;
    for (java.lang.reflect.Field f : wrappedConn.getClass().getDeclaredFields()) {
if (java.sql.Connection.class.isAssignableFrom(f.getType()))
connField = f;
    }
    if (connField==null)
throw new RuntimeException("Cannot get original JDBC connection from Tibco Wrapper");
    connField.setAccessible(true);
    java.sql.Connection oraConn = (java.sql.Connection) connField.get(wrappedConn);
    /* do the work */
}
catch (java.sql.SQLException sqle) {
sqle.printStackTrace();
ac.releaseConnection(sqle);
wrappedConn = null;
throw sqle;
}
catch (Throwable t) {
t.printStackTrace();
ac.releaseConnection();
wrappedConn = null;
throw new RuntimeException("Unexpected Java code error", t);
}
finally {
if (ps!=null) {
try {
ps.close();
}
catch (Exception e) {}
}
if (wrappedConn!=null)
ac.releaseConnection();
}

0 komentarze: