I've just spent some hours figuring out how to set up a configuration
for looking up datasources that works both for WSAD 5.1.1 and Tomcat
5.0.19,
and my experiences might be of interest to someone someday.
Given a Datasource with the name "jdbc/myDS".
This is how I look it up in WSAD:
Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY."com.ibm.websphere.naming.WsnInitialContextFactory");
environment.put(Context.PROVIDER_URL, "iiop:///");
Context theInitialContext = new InitialContext(environment);
DataSource theDataSource =
(DataSource)theInitialContext.lookup("jdbc/myDS");
For Tomcat, I use this:
Context theInitialContext = new InitialContext();
Context datasourceContext = theInitialContext.lookup("java:comp/env");
DataSource theDataSource =
(DataSource)datasourceContext.lookup("jdbc/myDS");
(WSAD does not use the context java:comp/env)
One other important difference, is that WSAD demands that username and
password be given as parameters
when retrieving a connection from the datasource, and fails if you try
to use the getConnection() without parameters.
Tomcat, on the other hand, uses DBCP, which throws an
UnsupportedOperationException if you use
the getConnection() with parameters.
So, the two are mutually exclusive, but the DBCP strategy is more
secure, since it does not require the
username and password to be available within the application.
If you use OJB, you must provide a different
jdbc-connection-descriptor
for WSAD than for Tomcat. Here's an example for Tomcat:
<jdbc-connection-descriptor
jcd-alias="jcd-alias-myDS"
default-connection="true"
platform="Oracle"
jdbc-level="2.0"
jndi-datasource-name="java:comp/env/jdbc/myDS"
batch-mode="false"
useAutoCommit="0"
ignoreAutoCommitExceptions="false"
The same for WSAD would be:
<jdbc-connection-descriptor
jcd-alias="jcd-alias-myDS"
default-connection="true"
platform="Oracle"
jdbc-level="2.0"
jndi-datasource-name="jdbc/myDS"
batch-mode="false"
useAutoCommit="0"
ignoreAutoCommitExceptions="false"
username="theUser"
password="thePassword"
Erik
kt - 07 Apr 2004 12:01 GMT
> I've just spent some hours figuring out how to set up a configuration
> for looking up datasources that works both for WSAD 5.1.1 and Tomcat
[quoted text clipped - 61 lines]
>
> Erik
Thanks man, you saved my skin!
I've been stuck on this for a long time, no thanks to the unhelpful
error message "java.lang.UnsupportedOperationException".