Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / April 2004

Tip: Looking for answers? Try searching our database.

JNDI Datasource lookup - differences between WSAD and Tomcat

Thread view: 
Erik G D. - 02 Apr 2004 08:23 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
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".


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.