JNDI is not tied to Tomcat, but you have to set the datasource inside
the container (for example Tomcat).
In Tomcat, in order to set a datasource inside the application you have
to deploy with your application the following "context.xml" file inside
the "meta-inf" directory:
<Context path="/ApplicationContextPath">
<Resource name="jdbc/DatabaseSource" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/DatabaseSource">
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>password</name>
<value>manager</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@127.0.0.1:1521:OracleDB</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>20</value>
</parameter>
<parameter>
<name>username</name>
<value>system</value>
</parameter>
</ResourceParams>
</Context>
If you use an Oracle DB.
Note that:
- this datasource is available only for the application and not for all
Tomcat applications.
If you want to use a global datasource you can use the Tomcat web
amministration tool.
- You have to know the url of the DB server. But you can set it using
the Tomcat web amministration tool.
BR
/Amleto
-----Messaggio originale-----
Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Inviato: marted� 21 settembre 2004 11.32
A: [EMAIL PROTECTED]
Oggetto: Re: Assigning a DataSource to a Business Delegate on startup
> you can use JNDI to get a DataSource (if you use tomcat see tomcat
> documentation in order to set the datasource). Here an example code to
> use inside the singleton object:
>
> //Get DB from JNDI
> try {
> Context initCtx = new InitialContext();
> Context envCtx = (Context) initCtx.lookup("java:comp/env");
> DataSource dataSource = (DataSource)
> envCtx.lookup("jdbc/DatabaseSource");
>
> } catch ( NamingException e ) {
> //Handle Source Code Exception
> }
>
This is a nice solution, but I would like to use the DataSource
configuration in struts-config.xml. I noticed that there is the
"ConfigHelper.getDataSource()" method to get the default data source,
but I want to use a DataSource that I mapped with a key. By the way, the
solution above is not too tied to Tomcat? What if I want to distribute
my application? Do I have to configure Tomcat on the other machine? Ciao
Antonio Petrelli
>
>
>
> -----Messaggio originale-----
> Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Inviato: marted� 21 settembre 2004 11.11
> A: [EMAIL PROTECTED]
> Oggetto: Assigning a DataSource to a Business Delegate on startup
>
>
> Hello there,
> is there a way I can assign a DataSource to a singleton object (i.e. a
> Business Delegate) on startup? I know there is the "getDataSource"
> protected method in Action, but I have to pass the DataSource itself
> on each call of the delegate, or I have to check whether it has been
> already passed or not. Maybe it could be done with a plugin. In this
> case, is there already a package that I could use? And if not, how can
> I access to a DataSource outside the Action class? Thanks in advance
> Ciao Antonio Petrelli
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]