|
| jndi binding of a datasource |
 |
Fri, 14 Dec 2007 04:28:43 EST |
Hi,<br />
I am doing connection pooling in my workspace.<br />
<hr /><br />
**CODE**<br />
<hr /><br />
try<br />
{<br />
if(conn == null || conn.isClosed())<br />
{ <br />
//retrieve a datasource through the JNDI Naming Service<br />
<br />
java.util.Properties parms = new java.util.Properties();<br />
parms.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.web
sphere.naming.WsnInitialContextFactory");<br />
<br />
//Create the Initial Naming Context<br />
javax.naming.Context ctx = new javax.naming.InitialContext(parms);<br />
<br />
//Lookup through the naming service to retrieve a DataSourceobject<br />
//javax.sql.DataSource ds =
(javax.sql.DataSource)ctx.lookup("java:/comp/env/jdbc/ds1");<br
/>
javax.sql.DataSource ds =
(javax.sql.DataSource)ctx.lookup("jdbc/ds1");<br />
<br />
//Obtain a connection from DataSource<br />
java.sql.Connection conn = ds.getConnection();<br />
}<br />
}<br />
catch(Exception e)<br />
{<br />
e.printStackTrace();<br />
// <br />
}<br />
<br />
**------------------------------------------------------------------------------
-------------------------------<br />
ibm-web-bnd.xmi <br />
**------------------------------------------------------------------------------
--------------------------------<br />
<br />
<?xml version="1.0" encoding="UTF-8"?><br
/>
<webappbnd:WebAppBinding xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_1"
virtualHostName="default_host"><br />
<webapp href="WEB-INF/web.xml#WebApp"/><br />
<resRefBindings xmi:id="ResourceRefBinding_1197539406046"
jndiName="jdbc/ds1"><br />
<bindingResourceRef
href="WEB-INF/web.xml#ResourceRef_1197539406046"/><br />
</resRefBindings><br />
</webappbnd:WebAppBinding><br />
<hr /><br />
<br />
***-----------------------------------------------------------------------------
---------------------<br />
web.xml entry<br />
***-----------------------------------------------------------------------------
----------------------<br />
<br />
<resource-ref id="ResourceRef_1197539406046"><br
/>
<description>ds1</description><br />
<res-ref-name>jdbc/ds1</res-ref-name><br />
<res-type>javax.sql.DataSource</res-type><br
/>
<res-auth>Application</res-auth><br />
<res-sharing-scope>Shareable</res-sharing-scope><
br />
</resource-ref><br />
<p />
********************************************************************************
*****************************<br />
log message<br />
********************************************************************************
*****************************<br />
<br />
12/13/07 15:59:50:406 IST 6b01056d ConnectionFac I J2CA0122I: Resource reference
jdbc/ds1 could not be located, so default values of the following are used:
Resource-ref settings<br />
<br />
res-auth: 1 (APPLICATION)<br />
res-isolation-level: 0 (TRANSACTION_NONE)<br />
res-sharing-scope: true (SHAREABLE)<br />
res-resolution-control: 999 (undefined)<br />
Other attributes<br />
<br />
isCMP1_x: false (not CMP1.x)<br />
isJMS: false (not JMS)<br />
<br />
//////////////////////////////////////////////////AND ALSO<br />
nullpointer exception where conn.preparedStatement is used<br />
<p />
|
| Post Reply
|
|
|
|
|
|
|
|
|
|