Topic
No replies
SystemAdmin
SystemAdmin
1215 Posts
ACCEPTED ANSWER

Pinned topic regarding binding of datasource to jndi naming and lookup during connection

‏2007-12-13T10:32:03Z |
Hi,
I am doing connection pooling in my workspace.
<hr />
**CODE**
<hr />
try
{
if(conn == null || conn.isClosed())
{
//retrieve a datasource through the JNDI Naming Service

java.util.Properties parms = new java.util.Properties();
parms.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");

//Create the Initial Naming Context
javax.naming.Context ctx = new javax.naming.InitialContext(parms);

//Lookup through the naming service to retrieve a DataSourceobject
//javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("java:/comp/env/jdbc/ds1");
javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("jdbc/ds1");

//Obtain a connection from DataSource
java.sql.Connection conn = ds.getConnection();
}
}
catch(Exception e)
{
e.printStackTrace();
//
}

**-------------------------------------------------------------------------------------------------------------
ibm-web-bnd.xmi
**--------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_1" virtualHostName="default_host">
<webapp href="WEB-INF/web.xml#WebApp"/>
<resRefBindings xmi:id="ResourceRefBinding_1197539406046" jndiName="jdbc/ds1">
<bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1197539406046"/>
</resRefBindings>
</webappbnd:WebAppBinding>
<hr />
***--------------------------------------------------------------------------------------------------
web.xml entry
***---------------------------------------------------------------------------------------------------

<resource-ref id="ResourceRef_1197539406046">
<description>ds1</description>
<res-ref-name>jdbc/ds1</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
*************************************************************************************************************
log message
*************************************************************************************************************

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

res-auth: 1 (APPLICATION)
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
res-resolution-control: 999 (undefined)
Other attributes

isCMP1_x: false (not CMP1.x)
isJMS: false (not JMS)

//////////////////////////////////////////////////AND ALSO
nullpointer exception where conn.preparedStatement is used
KINDLY HELP