> 
> I already sent this to tomcat-dev but got no response. I'm 
> sending it here as
> well since this list may be more appropriate.
> 

It's more apropiate, sure :)

> This may be a stupid question but I've found hundreds of 
> messages from confused
> users on the subject of JDBC Realms and Tomcat and no good 
> explanation or
> example. There is a documentation file JDBCRealm.howto but it 
> doesn't describe
> how to instantiate the datasource with a code example or what 
> additional
> property files need to be included to configure jndi properties.
> 

JDBCRealm is not related to datasources.. is only a way to store user
data for use of the container managed authentication instead of the xml
tomcat-users files .. so JDBRealm is not related to what you need ..


> Like lots of other people, I'm trying to use the release 
> Tomcat 3.2.2, configure
> multiple jdbc datasources in the server.xml file, and 
> reference it in my
> servlet. I am only interested in using a shared database ID 
> to connect to the
> database for all users of my servlet. The database connect 
> info needs to be in
> Tomcat conf files since the passwords need to be reconfigured 
> at deployment time
> outside my war file.
> 
> 1. Is this behavior supported by Tomcat 3.2.2? How do I 
> configure multiple
> database datasources and instantiate them in my code?
> 
> 2. Assuming I setup the datasources like below, what 
> properties do I use to
> assign a name to the datasource so I can reference it?
> 
> <RequestInterceptor 
>     className="org.apache.tomcat.request.JDBCRealm" 
>     debug="99" 
>     driverName="oracle.jdbc.driver.OracleDriver"
>     connectionURL="jdbc:oracle:thin:@ntserver:1521:ORCL"
>     connectionName="scott"
>     connectionPassword="tiger"
> />
> 
> <RequestInterceptor 
>     className="org.apache.tomcat.request.JDBCRealm" 
>     debug="99" 
>     driverName="oracle.jdbc.driver.OracleDriver"
>     connectionURL="jdbc:oracle:thin:@ntserver2:1521:ORCL"
>     connectionName="scott"
>     connectionPassword="tiger"
> />
> 
> 
> 3. What do I need to add to a config file in order to access 
> the initial context
> so I can retrieve the datasource?
> 
> import javax.servlet.*;
> import javax.servlet.http.*;
> import javax.naming.*;
> import javax.sql.*;
> 
> String          theDataSourceName = "???";
> String          theNamingProviderURL = "???";
> String          theInitialContextNamingFactory = "???";
> Properties theProperties = new Properties (); 
> theProperties.put("java.naming.provider.url", theNamingProviderURL);
> theProperties.put("java.naming.factory.initial",theInitialCont
extNamingFactory);
> 
> Context theInitialContext = new InitialContext(theProperties);
> DataSource theDataSource = (DataSource) theInitialContext.lookup
> (theDatasourceName);
> 
> 



Saludos ,
Ignacio J. Ortega

Reply via email to