• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

javax.naming.NameNotFoundException: in context "java:comp/env"

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have developed a servlet based application (war) on tomcat, which I am trying to port to WAS. I am getting following Exception:

java.sql.SQLException: Error looking up data source for name: jdbc/MySQLDB
Caused by: javax.naming.NameNotFoundException: Name jdbc not found in context "java:comp/env".
at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1767)
at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1083)
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:991)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1263)
at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:384)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1307)

Here is the details about application:

Flow OF Execution is like 1. JMS Broker Servlet Context Listener starts the ActiveMQ 2. JMS client gets initialized
from StartUpServlet 3. Servlet trying to lookup DataSource throws java.sql.SQLException: Error looking up data
source for name: jdbc/MySQLDB. If StartUpServlet gets commented out from web.xml then lookup for DataSource works fine.
But I need both of them to work together.


public class StartUpServlet extends GenericServlet
private Context jndiContext;

public void init() throws ServletException
Properties props = new Properties();
props.setProperty(Context.PROVIDER_URL, "tcp://localhost:61616");
jndiContext = new InitialContext(props);

QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory) jndiContext.lookup("queueConnectionFactory");
QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
Queue queue = (Queue) jndiContext.lookup("MyQueue");

<Context debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/MySQLDB"
maxActive="50" initialSize="5" />

Context context = (Context) new InitialContext().lookup("java:comp/env");
javax.sql.DataSource ds =(javax.sql.DataSource) context.lookup("jdbc/MySQLDB");
Connection sqlConnection = ds.getConnection() ;
statement = sqlConnection.prepareStatement(queryString);;

java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url = tcp://localhost:61616
onnectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactory
queue.MyQueue = MyQueue
queue.MyResponseQueue = MyResponseQueue

Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic