Skip to main content

LookUp Fails

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
12 replies [Last post]
samarthya
Offline
Joined: 2011-03-24

I am trying to use JDBC resource that I have defined for a connection pool (MySQL - connection).
1. The ping works fine for the JDBC Connection Pool.
2. The JDBC resource has been named jdbc/projectx.
3. I am accessing the resource using a standalone client on the same machine.
Everytime I exceute the standalone program I get an exception -
<code>
java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
Exception in thread "main" javax.naming.NamingException: Lookup failed for 'jdbc/projectx' in SerialContext
</code>
Any help pointers?
- Samarthya

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sm157516
Offline
Joined: 2005-03-28
arthury
Offline
Joined: 2010-09-16

How are you connecting to your Pool rsrc?
What are the steps you are taking?
Did every single step succeed?
Have succeeded in connecting to this Pool previously?
Did anything show up in the Server log?

On Tue, Mar 22, 2011 at 4:34 AM, wrote:

> Please see
> http://blogs.sun.com/technical/entry/lookup_from_standalone_client
>
>
> --
>
> [Message sent by forum member 'sm157516']
>
>
> View Post: http://forums.java.net/node/784040
>
>
>

--
Arthur Y.

samarthya
Offline
Joined: 2011-03-24

These are the steps I am following.

  1. InitialContext ic = new InitialContext();
    DataSource ds = (DataSource) ic.lookup(&quot;jdbc/dbName&quot;);
    <a name="63287"> </a>
  2.    Connection con =  ds.getConnection();
samarthya
Offline
Joined: 2011-03-24

I have even tried setting the properties for the Context using a hashmap - env.put(Context.PROVIDER_URL, "iiop://localhost:3700"); but still no use. Also it is a standalone application void main() - where in I am trying to access this resource.
- Samarthya

samarthya
Offline
Joined: 2011-03-24

env.put("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
env.put("org.omg.CORBA.ORBInitialPort", "3700");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");

I have tried to put these settings as well, but I still get exception

<code>
Exception in thread "main" javax.naming.NamingException: Lookup failed for 'jdbc/projectx' in SerialContext targetHost=127.0.0.1,targetPort=3700 [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext targetHost=127.0.0.1,targetPort=3700 [Root exception is java.lang.NullPointerException]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at test.jndi.TestJndi.main(TestJndi.java:36)
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext targetHost=127.0.0.1,targetPort=3700 [Root exception is java.lang.NullPointerException]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
... 2 more
Caused by: java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
... 3 more

</code>

What is that I am missing. I have no clue... :(

sm157516
Offline
Joined: 2005-03-28

If you are using glassfish 3.1, try to do the following :
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
props.put(Context.PROVIDER_URL, "service:jmx:rmi://HOSTNAME:8686/jndi/rmi://HOSTNAME:8686/jmxrmi");
try
Context ctx = new InitialContext(props);
Object ref = ctx.lookup("jdbc/__default");
DataSource ds = (DataSource)PortableRemoteObject.narrow(ref, DataSource.class);
Connection con = ds.getConnection();
} catch(Exception ex) {
}
In the above, you could also substitute Context.PROVIDER_URL with IIOP://localhost:3700.
Compile the program, and include $S1AS_HOME/lib/gf-client.jar in your classspath while executing. Hope this helps.

samarthya
Offline
Joined: 2011-03-24

I am using Open Glass Fish and there is no GF-Client.jar in the lib, the only thing closes I found (for the context factory) was glassfish-naming.jar which has the definitions. Also I tried using the said modifications, but it did not work. :(

mvatkina
Offline
Joined: 2005-04-04

May be you have not a complete installation. You need to have
gf-client.jar in your classpath which is referenced from the GlassFish
install location (not copied over to another place).

forums@java.net wrote:
> I am using Open Glass Fish and there is no GF-Client.jar in the lib,
> the only
> thing closes I found (for the context factory) was
> glassfish-naming.jar which
> has the definitions. Also I tried using the said modifications, but
> it did
> not work. :(
>
>
> --
>
> [Message sent by forum member 'samarthya']
>
> View Post: http://forums.java.net/node/784040
>
>

samarthya
Offline
Joined: 2011-03-24

The only thing I see is
<code>
javax.naming.NamingException: Lookup failed for 'jdbc/projectx' in SerialContext targetHost=localhost,targetPort=3700 [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext targetHost=localhost,targetPort=3700 [Root exception is java.lang.NullPointerException]]
</code>

sm157516
Offline
Joined: 2005-03-28

glassfish-naming.jar is not enough. Which version of glassfish are you using? Could you specify?

samarthya
Offline
Joined: 2011-03-24

GlassFish 3.0.1 - (Open Glass Fish)

samarthya
Offline
Joined: 2011-03-24

Thanks for the comment. I did find this link and did try using the IIOP port 3700.
iiop://localhost:3700 but it did not work for me, is it that the only option is through command line? Can it be done programmatically? The reason I am asking this is because whenever I tried setting the values for the Context.<Some constant> it never resulted in success.
Thanks!
- Samarthya