Using Weblogic JDBC connection pool

There are two ways to use weblogic datasource to get database connection pool.

1. To use datasource that hosts in another weblogic, we can use t3 protocol

 Properties p=new Properties();
 p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
 p.put(Context.PROVIDER_URL,"t3://hostname_of_weblogic:7001");</pre>
p.put(Context.SECURITY_PRINCIPAL, pUsername);
p.put(Context.SECURITY_CREDENTIALS, pPassword);
<pre>
 InitialContext ctx=new InitialContext(p);
 DataSource ds=(DataSource)ctx.lookup("myAppDbPool");
 Connection con=ds.getConnection();

2. To use datasource from the same weblogic server (that hosts your application)

 InitialContext ctx=new InitialContext();

DataSource ds=(DataSource)ctx.lookup("java:comp/env/myAppDbPool");
 Connection connection=ds.getConnection();

In your web application, you will need a web.xml entry and an entry in a new file weblogic.xml

web.xml


<resource-ref>
 <res-ref-name>myAppDbPool</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>
 </resource-ref>

weblogic.xml


<!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 8.1//EN"

"http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd">

<weblogic-web-app>

<reference-descriptor>
 <resource-description>
 <res-ref-name>myAppDbPool</res-ref-name>
 <jndi-name>myAppDbPool</jndi-name>
 </resource-description>
 </reference-descriptor>

</weblogic-web-app>

(Visited 19 times, 1 visits today)