I am having problem in looking up datasource in WSAD 5.1 (not in WAS) from a stand alone app.
Following are my configurations:
Datasource tab in WSAD:
Name - DB2SARM
JNDI Name - jdbc/sarmDB
Componen-ManagedAuthentication Alias: sarmDBAlias
Container-managed authentication alias: sarmDBAlias
Security tab:
Alias - sarmDBAlias
User ID - scott
I have not used Admin console.
My Java code:
public class ServerConnector {
public Connection getSARMConnection() {
Connection conn = null;
try {
Hashtable properties = new Hashtable();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
properties.put(Context.PROVIDER_URL, "iiop://localhost:9816");
Context initialContext = new InitialContext(properties);
DataSource ds = (DataSource)initialContext.lookup("DB2SARM");
//DataSource ds = (DataSource)initialContext.lookup("sarmDB");
//DataSource ds = (DataSource)initialContext.lookup("sarmDB");
//DataSource ds = (DataSource)initialContext.lookup("sarmDBAlias");
//DataSource ds=
(DataSource)initialContext.lookup("java:comp/env/sarmDBAlias");
//DataSource ds = (DataSource)initialContext.lookup("jdbc/sarmDB");
//DataSource ds =
(DataSource)initialContext.lookup("java:comp/env/sarmDB")
conn = ds.getConnection();
}
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?