Alejandro,

I've dealt with a similar problem by utilizing the Primrose database connection pool (http://www.primrose.org.uk/) for my application in desktop mode. I've used MySQL or postgreSQL, and used Tomcat's db pool when my app runs in web mode. For desktop mode, one sets up a Primrose configuration xml file; then the startup code for the desktop mode uses similar code to obtain a datasource, something like this:

        Context ctx = new InitialContext();
        if (_siDAOBase == null ){
String key = "java:comp/env/" + "jdbc" + "/" + DatabaseConstants.MY_DB;
                DataSource ds = (DataSource)ctx.lookup(key);
                if (ds != null ){
                    SI_DAOBase.setDataSource(ds);
                    _siDAOBase = new SI_DAOBase();
                }
        }

After that, I'm using my same jars as in the web mode. The trick was to create a DAO object (SI_DAOBase above) which holds the datasource, and hands out connections it obtains from the datasource. The call SI_DAOBase.setDataSource(ds); sets the datasource -- it's invoked in my AppListener in web mode, and in the startup code above in desktop mode.

Hope this helps,
Ken Bowen

On Jul 22, 2008, at 3:51 PM, Alejandro Hernandez Angeles wrote:

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.initial=org.apache.naming.java.javaURLContextFactory -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(NamingContext.java:345)
       at org.apache.naming.NamingContext.list(NamingContext.java:368)
       at javax.naming.InitialContext.list(InitialContext.java:436)
       at MyDesktopApp.main(MyDesktopApp.java:12)

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: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to