I tried several ways to get datasource that is bound to jndi. Obviously, my WSAD Test server is running on port 9816.
Follwing are the key value pairs that I can read from JNDI: com.ibm.websphere.naming.hostname.normalizer : com.ibm.ws.naming.util.DefaultHostnameNormalizer java.naming.factory.initial : com.ibm.websphere.naming.WsnInitialContextFactory com.ibm.websphere.naming.name.syntax : jndi com.ibm.websphere.naming.namespace.connection : lazy com.ibm.ws.naming.ldap.ldapinitctxfactory : com.sun.jndi.ldap.LdapCtxFactory com.ibm.websphere.naming.jndicache.cacheobject : populated com.ibm.websphere.naming.namespaceroot : defaultroot com.ibm.ws.naming.implementation : WsnIpCos com.ibm.ws.naming.wsn.factory.initial : com.ibm.ws.naming.util.WsnInitCtxFactory com.ibm.websphere.naming.jndicache.maxcachelife : 0 com.ibm.websphere.naming.jndicache.maxentrylife : 0 com.ibm.websphere.naming.jndicache.cachename : providerURL java.naming.provider.url : iiop://localhost:9816 java.naming.factory.url.pkgs : com.ibm.ws.naming:com.ibm.ws.naming
As such, I can bind to JNDI. But lookup is not successfull.
If I do lookup on sarmDB, or sarmDBAlias, DB2SARM directly (instead of java:comp/env), I get error like:
javax.naming.NameNotFoundException: Context: localhost/nodes/localhost/servers/server1, name: DB2SARM: First component in name DB2SARM not found. Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL mg.org/CosNaming/NamingContext/NotFound:1.0
If I try to look up using ava:comp/env/sarmDBAlias, I get error like:
javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
What is the correct way of looking up datasource in WSAD from Standalone app?
The iiop port is 2809.Also you need not not specify these settings as 5.1 provides these settings by default so can just create the context and do the lookup.
Joined: Jul 21, 2003
Gavi: I think you missed the problem statement. iiop port number can be changed. I run 2 WSAD Test servers on 2 different iiop ports to simulate remote lookup of EJBs. Default port number of 2809 can be changed.
Also, if your application runs in web container, jars are available in classpath. However, if you want to do lookup from a POJO, it requires setting up extra stuff in InitialContext.
However, I resolved my problem. I can now look up my datasource from jndi.
But it is now throing exception when I call getConnection() on that datasource.
Username and pwd are set in Security tab of WSAD configuration of that datasource. I think I am not getting connected cause of security constraint.
I get error below. Any thoughts?
Has anyone encountered Mapping the following SQLException, with ErrorCode -1,013 and SQLState 08001, to a StaleConnectionException: COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver] SQL1013N The database alias name or database name "SAMPLE" could not be found. SQLSTATE=42705
Pleasde note that the datasource and databse name is different from SAMPLE that I see in exception. There is no database called SAMPLE. I am connecting to DB2 database. SAMPLE may be something used by DB2 itself. Name of database schema is not SIMPLE either.
Joined: Apr 28, 2005
Try switching to DB perspective and create the connection from it.
author & internet detective
Sam, When you create a db2 DatasSOurce in WSAD , it uses the SAMPLE database by default. If you open up the server in the server perspective and go to the database tab, you can see this. Look at the properties for your datasource (at the bottom of the screen.) It should be around the second or third property. Just change this to the name of your db.
For future reference, note that we have an IBM/WebSphere forum further down. You may get faster answers there as that is where the WSAD/WAS gurus hang out.