[jboss-user] [JNDI and Naming] - Context Lookup error

Mohamed Mostafa do-not-reply at jboss.com
Mon Apr 9 09:33:08 EDT 2012

Mohamed Mostafa [https://community.jboss.org/people/mohamedmostafa] created the discussion

"Context Lookup error"

To view the discussion, visit: https://community.jboss.org/message/728891#728891

i will explain my project breifly

I need to create a webservice which calls an EJB that execute a query on a sybase database
this database is a datasource on glassfish server ( i am using Netbeans 7.1.1 ) 

i have created Stateless session EJB which i needs it to connect to the database using JNDI 

here is a part of the class

public class NewSessionBean implements NewSessionBeanLocal {
    @Resource(name = "ejb")
    private DataSource ejb;
    public String execute(String query) {
        String dbName = "java:comp/env/jdbc/ejb";
        try {
            Context loContext = (Context) new InitialContext().lookup("java:comp/env");
            ejb = (DataSource)loContext.lookup("jdbc/ejb");
            Connection loConnection = ejb.getConnection();

and the glassfish.xml found in the configuration files of the EJB project is


when i run the code it always gives an error at that line 

Context loContext = (Context) new InitialContext().lookup("java:comp/env");

i have tried many lookups like

Context loContext = (Context) new InitialContext().lookup("java:comp/env/jdbc/ejb");

HINT: my JNDI name i want to use is: jdbc/ejb

always giving me that error

> run:
> Apr 9, 2012 3:26:35 PM bean.NewSessionBean execute
> SEVERE: null
> javax.naming.NamingException: Lookup failed for 'java:comp/env' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Invocation exception: Got null ComponentInvocation ]
>     at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
>     at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
>     at javax.naming.InitialContext.lookup(InitialContext.java:392)
>     at bean.NewSessionBean.execute(NewSessionBean.java:35)
>     at bean.Main.main(Main.java:14
> )
> Caused by: javax.naming.NamingException: Invocation exception: Got null ComponentInvocation 
>     at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.getComponentId(GlassfishNamingManagerImpl.java:873)
>     at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:742)
>     at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:177)
>     at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)
Please anyone help me if anything still unclear i will provide you with all you need i need this solution urgently.

Reply to this message by going to Community

Start a new discussion in JNDI and Naming at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120409/e87e0417/attachment.html 

More information about the jboss-user mailing list