tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sameer Acharya <>
Subject Re: Trying to mix db connection pooling on web and desktop applications
Date Wed, 23 Jul 2008 03:54:19 GMT
As I see it you are mixing two different things, your web application will always run inside
Tomcat server but your desktop application can be anywhere(not just on TC server).

The simplest way to do this might be to write your own database connection helper class which
would go to the context (step 6) and use Tomcat datasource to get connections when you are
running under TC.

And in desktop mode you have your own connection pooler (or just create a simple db connection
) to get a db connection.

so your getConnection method on helper would do the following logic :

Is in desktop mode 
  get my pooler/connection
 //under TC
  get connection with logic as in step 6


--- On Wed, 7/23/08, Alejandro Hernandez Angeles <> wrote:

> From: Alejandro Hernandez Angeles <>
> Subject: Trying to mix db connection pooling on web and desktop applications
> To:
> Date: Wednesday, July 23, 2008, 1:21 AM
> Hello, this is the scenario:
> I have an application that must have two interfaces: as a
> desktop application and as a web application
> I've put the business logic inside a JAR library
> (client_bpm.jar), which must connect to an Oracle 9i
> database
> I configured the web application so it can use a db pool
> connection, in the following manner:
> 1. Added to %CATALINA_HOME%/conf/server.xml the following:
>   <Server>
>     <GlobalNamingResources>
>       <Resource name="jdbc/RAM_DB"
>             auth="Container"
>             type="javax.sql.DataSource"
>             username="*****"
>             password="*****"
> driverClassName="oracle.jdbc.OracleDriver"
> 	    url="jdbc:oracle:thin:*****"
> 	    removeAbandoned="true"
> 	    removeAbandonedTimeout="60"
> 	    logAbandoned="true"
>             maxActive="8"
> 	    maxIdle="4"
> 	    maxWait="2000"/>    
>     </GlobalNamingResources>
>   </Server>
> 2. Added to %CATALINA_HOME%/conf/context.xml the following:
>   <ResourceLink 
>     name="jdbc/RAM_DB"
>     global="jdbc/RAM_DB"
>     type="javax.sql.DataSource"
>   />
> 3. Added to
> %CATALINA_HOME%/webapps/myWebApp/WEB-INF/web.xml the
> following:
>   <resource-ref>
>     <description>
>       Resource reference to a factory for
> java.sql.Connection
>       instances that may be used for talking to a
> particular
>       database that is configured in the Context
>       configurartion for the web application.
>     </description>
>     <res-ref-name>
>       jdbc/RAM_DB
>     </res-ref-name>
>     <res-type>
>       javax.sql.DataSource
>     </res-type>
>     <res-auth>
>       Container
>     </res-auth>
>   </resource-ref>
> 4. Added my business library (client_bpm.jar) to
> %CATALINA_HOME%/webapps/myWebApp/WEB-INF/lib
> 5. Added JDBC library (ojdbc14.jar) to %CATALINA_HOME%/lib
> 6. Use the following code to get a db connection:
>   Context initCtx = new InitialContext();
>   Context envCtx = (Context)
> initCtx.lookup("java:comp/env");
>   DataSource ds = (DataSource)
> envCtx.lookup("jdbc/RAM_DB");
>   Connection conn= ds.getConnection();
> And the web application runs fine, i have no problems with
> it
> Now, what i want is to use the same db connection pool
> facility (that Tomcat provides to web applications) on my
> desktop application, and use the same code (or something
> very similar) i used in point 6 to obtain a db connection
> With points 1-3 Tomcat provided my web application with a
> db connection pooling facility
> I want Tomcat to provide to my desktop application the same
> db connection pooling facility, ¿How do i do that?
> I have tried invoking my desktop application with the
> following:
> java -classpath
> ".;%CATALINA_HOME%/webapps/myWebApp/WEB-INF/lib/client_bpm.jar;%CATALINA_HOME%/lib/catalina.jar;%CATALINA_HOME%/bin/tomcat-juli.jar;%CATALINA_HOME%/lib/ojdbc14.jar"
> -Djava.naming.factory.url.pkgs=org.apache.naming
> MyDesktopApp
> And got the following error:
> javax.naming.NameNotFoundException: Name java: is not bound
> in this Context
>         at
> org.apache.naming.NamingContext.list(
>         at
> org.apache.naming.NamingContext.list(
>         at
> javax.naming.InitialContext.list(
>         at MyDesktopApp.main(
> Any suggestions will be appreciated
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> Aviso Confidencial.-
> Este correo electrónico, así como los archivos adjuntos
> que contenga son confidenciales de conformidad con las
> leyes aplicables, y es para uso exclusivo del destinatario
> al que expresamente se le ha enviado. Si usted no es el
> destinatario legítimo del mismo, deberá reportarlo al
> remitente del correo y borrarlo inmediatamente. Cualquier
> revisión, retransmisión, divulgación, difusión o
> cualquier otro uso de este correo, por personas o entidades
> distintas a las del destinatario legítimo, queda
> expresamente prohibido. Los derechos de propiedad respecto
> de la información, material, bases de datos, diseños, y
> los distintos elementos en él contenidos son titularidad
> de Mapfre Tepeyac, S. A. Este correo electrónico no
> pretende ni debe ser considerado como constitutivo de
> ninguna relación legal, contractual o de otra índole
> similar.
> Confidencial Notice.-
> This e-mail, as such as the attached files it contains are
> confidential in accordance with the applicable laws, and is
> for exclusive use to expressly addressee has been sending.
> If you are not the legitimate addressee itself, you will
> must report to sender of mail and cross it immediately. Any
> review, re-transmission, disclosure, dissemination or any
> other use of this mail, from people or different entities
> from the legitimate addressee, is prohibited. The property
> rights about the information, material, databases, designs,
> and the different components in it contains are ownership of
>  MAPFRE Tepeyac, S. A. This e-mail do not pretend, neither
> it should be considered of any legal or contractual
> relationship.
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message