do you need to declare with jdbc for datasource?

ctx.lookup("java:comp/envjdbc//REQUEST");





"Varanasi, Ishwara" <[EMAIL PROTECTED]>

22/05/2006 02:23 PM

Please respond to
[email protected]

To
<[email protected]>
cc
Subject
Unable get datasource reference in bean...





Hi,
I am facing a problem with accessing DataSource.
I am able to get reference to a declared database pool in JSP and
Servlet.
But unable to do so in a session bean or class accessed by a session
bean. I am getting a NameNotFoundException... any idea why this is
happening?

The code:
InitialContext ctx = new InitialContext();

DataSource ds = (DataSource)
ctx.lookup("java:comp/env/REQUEST");

Connection con = ds.getConnection();

Web.xml:
<resource-ref>

<res-ref-name>REQUEST</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>

</resource-ref>

Geronimo-web.xml:
<naming:resource-ref>

<naming:ref-name>REQUEST</naming:ref-name>
<naming:resource-link>REQUEST</naming:resource-link>

</naming:resource-ref>

Output and stack trace of exception goes here:

Getting ref in Servlet:
==========================
09:46:39,342 INFO  [TimeServerServlet] 2. Getting ds ref in Servlet...
09:46:44,764 INFO  [TimeServerServlet] Got connection:
[EMAIL PROTECTED]
09:46:44,764 INFO  [DateTimeFunctions] Date          : Mon May 22
09:46:44 IST 2006
09:46:44,764 INFO  [DateTimeFunctions] Formatted Date: 22/05/2006
09:46:44.764 In ejbCreate()


Error in bean:
==========================
09:46:44,780 INFO  [TimeServerBean] 1. Getting ds ref in Bean...
09:46:44,780 ERROR [TimeServerBean] Exception #1:
javax.naming.NameNotFoundException: env/REQUEST
javax.naming.NameNotFoundException: env/REQUEST

at
org.apache.geronimo.naming.enc.AbstractReadOnlyContext.lookup(AbstractRe
adOnlyContext.jav
a:81)

at
org.apache.geronimo.naming.java.RootContext.lookup(RootContext.java:51)

at javax.naming.InitialContext.lookup(InitialContext.java:347)
at

com.nis.timeserver.ejb.TimeServerBean.getTime(TimeServerBean.java:72)
at

com.nis.timeserver.ejb.TimeServerBean$$FastClassByCGLIB$$3926a5ec.invoke
(<generated>)

at
org.openejb.dispatch.AbstractMethodOperation.invoke(AbstractMethodOperat
ion.java:90)

at
org.openejb.slsb.BusinessMethod.execute(BusinessMethod.java:67)

at
org.openejb.dispatch.DispatchInterceptor.invoke(DispatchInterceptor.java
:72)

at
org.apache.geronimo.naming.java.ComponentContextInterceptor.invoke(Compo
nentContextInterc
eptor.java:56)

at
org.openejb.ConnectionTrackingInterceptor.invoke(ConnectionTrackingInter
ceptor.java:81)

at
org.openejb.transaction.ContainerPolicy$TxRequired.invoke(ContainerPolic
y.java:119)

at
org.openejb.transaction.TransactionContextInterceptor.invoke(Transaction
ContextIntercepto
r.java:80)

at
org.openejb.slsb.StatelessInstanceInterceptor.invoke(StatelessInstanceIn
terceptor.java:98
)

at
org.openejb.transaction.ContainerPolicy$TxRequired.invoke(ContainerPolic
y.java:140)

at
org.openejb.transaction.TransactionContextInterceptor.invoke(Transaction
ContextIntercepto
r.java:80)

at
org.openejb.SystemExceptionInterceptor.invoke(SystemExceptionInterceptor
.java:82)

at
org.openejb.GenericEJBContainer.invoke(GenericEJBContainer.java:238)

at
org.openejb.proxy.EJBMethodInterceptor.intercept(EJBMethodInterceptor.ja
va:129)

at
org.openejb.proxy.SessionEJBObject$$EnhancerByCGLIB$$39d68ea2.getTime(<g
enerated>)

at
com.nis.timeserver.web.servlet.TimeServerServlet.doGet(TimeServerServlet
.java:88)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
at

org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.j
ava:252)

at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:173)

at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:213)

at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.java:178)

at
org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.inv
oke(GeronimoStand
ardContext.java:272)

at
org.apache.geronimo.tomcat.valve.TransactionContextValve.invoke(Transact
ionContextValve.j
ava:53)

at
org.apache.geronimo.tomcat.valve.ComponentContextValve.invoke(ComponentC
ontextValve.java:
47)

at
org.apache.geronimo.tomcat.valve.InstanceContextValve.invoke(InstanceCon
textValve.java:60
)

at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
:126)

at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:105)

at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
java:107)

at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:526
)

at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:1
48)

at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:85
6)

at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processC
onnection(Http11P
rotocol.java:744)

at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint
.java:527)

at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollow
erWorkerThread.ja
va:80)

at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool
.java:684)

at java.lang.Thread.run(Thread.java:534)


Thanks and Regards,
Ishwara Bhat V





***********************************************************

Please consider our environment before printing this email.

This email and any attachments may be confidential and contain privileged
 information. If you are not the intended recipient you must not use, 
disclose, copy or distribute this communication. If you have received 
this message in error please delete and notify the sender. When communicating 
by email you consent to the monitoring and recording of that correspondence.

The Attorney General's Department of NSW promotes a Just and Safe Society. 
Visit us at http://www.lawlink.nsw.gov.au

Reply via email to