import java.sql.Connection;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class OracleConnectionUtil
{
public static Connection getOracleConnection(String jndi)
try{
InitialContext ctx = new InitialContext();
DataSource datasource = (DataSource) ctx.lookup(jndi);
Connection connection = datasource.getConnection();
//cast this to JBoss specific WrappedConnection
org.jboss.resource.adapter.jdbc.WrappedConnection wrappedConnection = (org.jboss.resource.adapter.jdbc.WrappedConnection) connection;
//get the underlying connection (T4CConnection)
Connection underlyingConnection = wrappedConnection.getUnderlyingConnection();
//cast to T4CConnection if some specific API on this object is to be used
oracle.jdbc.OracleConnection t4cConnection = (oracle.jdbc.OracleConnection) underlyingConnection;
out.println("Oracle Connection : " + t4cConnection);
return t4cConnection;
}catch(Exception e) {
System.out.println("Exception while getting oracle connection :::: " + e.getMessage());
}
return null;
}
public static void close(Connection conn) {
try{
if( conn != null ) conn.close();
}catch(Exception e) {
// Ignore when the connection closing
}
}
}
// 오라클에서 얻어온 connection을 close할 경우 casting된 connection은 실제 connection이므로
// close시 실제 연결이 끊어지게 되는 현상이 발생합니다.
// 아래의 같이 DataSource의 proxy connection을 close해야만 WAS의 connection pool로 반환하게 됩니다.
Connection conn = DataSource.getConnection();
Connection oracleConn = conn.getUnderlyingConnection();
//Do JDBC stuff heere
//CLOSE THE HANDLE, NOT THE UNDERLYING CONNECTION!!!!
conn.close();
conn = DataSource.getConnection();
oracleConn = conn.getUnderlyingConnection();





