Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 38915 invoked from network); 2 Jul 2004 19:14:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 2 Jul 2004 19:14:49 -0000 Received: (qmail 56405 invoked by uid 500); 2 Jul 2004 19:14:23 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 56372 invoked by uid 500); 2 Jul 2004 19:14:23 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 56355 invoked by uid 99); 2 Jul 2004 19:14:23 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [200.252.157.99] (HELO dexter.tse.gov.br) (200.252.157.99) by apache.org (qpsmtpd/0.27.1) with ESMTP; Fri, 02 Jul 2004 12:14:18 -0700 Received: from dexter.tse.gov.br (dexter [127.0.0.1]) by localhost.tse.gov.br (Postfix) with ESMTP id 1232B12C8B1 for ; Fri, 2 Jul 2004 16:13:58 -0300 (BRT) Received: from brava.tre-sc.gov.br (unknown [10.9.1.12]) by dexter.tse.gov.br (Postfix) with ESMTP id 8FEED12C922 for ; Fri, 2 Jul 2004 16:13:57 -0300 (BRT) Received: from localhost (localhost [127.0.0.1]) by brava.tre-sc.gov.br (Postfix) with ESMTP id DD8C88615 for ; Fri, 2 Jul 2004 16:17:30 -0300 (BRT) Received: from brava.tre-sc.gov.br ([127.0.0.1]) by localhost (brava [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 17799-02 for ; Fri, 2 Jul 2004 16:17:28 -0300 (BRT) Received: from tre-sc.gov.br (elbassan.tre-sc.gov.br [10.9.7.58]) by brava.tre-sc.gov.br (Postfix) with ESMTP id 914FF70D8 for ; Fri, 2 Jul 2004 16:17:28 -0300 (BRT) Message-ID: <40E5B3C8.504@tre-sc.gov.br> Date: Fri, 02 Jul 2004 16:13:12 -0300 From: Emerson Cargnin Organization: TRE-SC User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: pt-br, en-us, en MIME-Version: 1.0 To: Tomcat Users List Subject: Re: How to use oracle pool instead of using DBCP pool? References: <5C6859B23203524195A81F6EED34F46D0C11DA@txdlls2msgusr13.itservices.sbc.com> In-Reply-To: <5C6859B23203524195A81F6EED34F46D0C11DA@txdlls2msgusr13.itservices.sbc.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at tre-sc.gov.br X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N I use another pool, but I have some context params, as I put below, and a pool servlet that instantiate all the pools and centralizes the connections. So you can see the connection state from a central point. If some is interested i can make it available. The only think you have to change is the pool creation. This way, apps can share pools (I know that dbcp can do it too, it didn't exist at that time) and to add a new one, just change this file. Beyond that, you have to put the jar with the lib in common lib, so every app will get the same pool manager. Names of parameters are in portuguese, but i think you can get the idea. alias1 ca... host1 hostvalue1 senha1 thepassword1 sid1 databasename1 user1 username alias2 descartaweb user2 usename2 senha2 pass2 host2 hostname2 sid2 adm SANTOS, DANIEL (SBCSI) wrote: > I use a method similar to this as well. I don't use a servlet listener however. I use a javax.servlet.ServletContextListener instead however. I store the jdbd url in my web.xml also as a context-param (I just just cram it all into one paramater however) and put the pool as an attribute of the Context. Here is the shorthand for that below: > > public void contextInitialized(ServletContextEvent sce) { > String dbUrl = sce.getServletContext().getInitParameter("dbUrl") > OracleDataSource pool = new OracleDataSource(); > pool.setURL(dbUrl); > sce.getServletContext().setAttribute("dbConnectionPool", pool); > } > > and I have my classes12.zip (renamed to .jar) in my WEB-INF/lib folder > -----Original Message----- > From: David Short [mailto:dshort@san.rr.com] > Sent: Friday, July 02, 2004 12:40 PM > To: 'Tomcat Users List' > Subject: RE: How to use oracle pool instead of using DBCP pool? > > > I'm sure there's another way. This is how I use it. You can extract the > connection pool logic and embed in your framework. > > -----Original Message----- > From: Claudio Carvalho [mailto:claudio@powerlogic.com.br] > Sent: Friday, July 02, 2004 10:33 AM > To: Tomcat Users List; dshort@san.rr.com > Subject: Re: How to use oracle pool instead of using DBCP pool? > > > Hi Davi, > > Thanks, but I'm trying to solve this problem without changing my J2EE > framework... using JNDI,etc... > Do you know any other approach? > > Claudio Carvalho. > > ----- Original Message ----- > From: "David Short" > To: "'Tomcat Users List'" > Sent: Friday, July 02, 2004 1:55 PM > Subject: RE: How to use oracle pool instead of using DBCP pool? > > > >>Try this. >> >>Here's how I do it using Struts on W2K. Modify names and paths to suit > > your > >>needs. >> >>Upon startup, a listener servlet (ResourceManagerListener) is called (See >> tag in the included web.xml source). >> >>The listener servlet will create the connection pool based on your web.xml >>parameters (See ResourceManagerListener.java). Once started, the listener >>servlet initializes an application scope variable (appDataSource), which >>when called from your servlets/JSPs will return a DB DataSource object (DB >>connection). >> >>-------------------------------------------------------------------------- > > -- > >>--------------------------- >> >>In your main servlet: >> >>try >> { >> DataSource ds = (DataSource) >>getServlet().getServletContext().getAttribute("appDataSource"); >> xxxProcess = new xxxProcessBean(); >> xxxInfo = new xxxInfoBean(); >> xxxProcess.setDataSource(ds); >> xxxInfo = xxxProcess.getUser(userName, customerId); >> } >> >>In your process bean: >> >>public class xxxProcessBean implements Serializable >> { >> private DataSource dataSource; >> >> /** >> * Sets the dataSource property value. >> */ >> public void setDataSource(DataSource dataSource) >> { >> this.dataSource = dataSource; >> } >> >> >> public xxxInfoBean getUser(String userName, String customerId) >> throws SQLException >> { >> // Get the user info from the database >> Connection conn = dataSource.getConnection(); >> xxxInfoBean xxxResult = null; >> >> try >> { >> xxxResult = getUserName(userName, customerId, conn); // Execute >>actual SQL statement. >> } >> >> finally >> { >> try >> { >> conn.close(); >> conn = null; >> } >> >> catch (SQLException e) >> {} // Ignore >> >> return xxxResult; >> >>-------------------------------------------------------------------------- > > -- > >>--------------------------- >> >>Change MachineNameHere to your machine name. >>Change OracleSIDHere to your DB SID. >>Change DBUserNameHere to your DB username. >>Change DBPasswordHere to your DB password >>Change ApplicationNameHere to a meaningful application designator. >>Change xxx to your object name. >> >>Copy Oracle's classes12.zip and nls_charset12.zip files (should live in >>C:\OraHome\jdbc\lib) to C:\Tomcat\common\lib. Depending on the version of >>Tomcat, you may need to rename the .zip files to .jar. >> >> >>I'll let you read/learn about Struts on your own. >> >>Hoe this helps. >> >>Dave >> >>-------------------------------------------------------------------------- > > -- > >>--------------------------- >>web.xml >> >> >>> PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" >> "http://java.sun.com//dtd/web-app_2_3.dtd"> >> >> >> >> >> javax.servlet.jsp.jstl.fmt.fallbackLocale >> en >> >> >> >> >> >> >> >> jdbcURL >> >> jdbc:oracle:oci8:@OracleSIDHere >> >> >> >> user >> DBUserNameHere >> >> >> >> password >> DBPasswordHere >> >> >> >> maxLimit >> 50 >> >> >> >> >> minLimit >> 10 >> >> >> >> >> accessControl >> >> com.ApplicationNameHere.servlets.AccessControlFilter >> >> >> loginPage >> /jsp/login.jsp >> >> >> >> >> accessControl >> /protected/* >> >> >> >> >> com.ApplicationNameHere.servlets.ResourceManagerListener >> >> >> >> >> >> action >> org.apache.struts.action.ActionServlet >> 1 >> >> >> >> >> errorDispatcher >> >> > com.ApplicationNameHere.servlets.ErrorDispatcherServlet >>let-class> >> >> errorPage >> /jsp/error/errorpage.jsp?debug=log >> >> >> >> >> >> action >> *.do >> >> >> >> errorDispatcher >> /errorDispatcher >> >> >> >> >> 1 >> >> >> >> >> java.lang.Throwable >> /errorDispatcher >> >> >> >> 500 >> /errorDispatcher >> >> >> >> java.sql.SQLException >> /errorDispatcher >> >> >> >> jdbc/ApplicationNameHere >> javax.sql.DataSource >> Container >> >> >> >> >>-------------------------------------------------------------------------- > > -- > >>--------------------------- >>ResourceManagerListener.java >>package com.ApplicationNameHere.servlets; >> >>import javax.servlet.*; >>import javax.servlet.http.*; >> >>import oracle.jdbc.pool.*; >> >>import javax.naming.*; >>import javax.sql.*; >> >>import java.sql.*; >>import java.math.*; >>import java.util.*; >> >>/** >> * This class manages the DataSource resource for an application, >> * creating an Oracle DataSource with pooling capabilities >> * and makes it available when the application starts and removes it >> * when the application is shut down. >> * >> * @author David Short, Relational Concepts, Inc. >> * @version David Short 01/10/2004 initial release. >> */ >>public class ResourceManagerListener implements ServletContextListener >> { >> private OracleConnectionCacheImpl ds = null; >> private Context ctx = null; >> >> public void contextInitialized(ServletContextEvent sce) >> { >> ServletContext application = sce.getServletContext(); >> >> /* >> * Get the JDBC URL, user, password and limits from the web.xml >> * context init parameters >> */ >> String jdbcURL = application.getInitParameter("jdbcURL"); >> String user = application.getInitParameter("user"); >> String password = application.getInitParameter("password"); >> String minLimit = application.getInitParameter("minLimit"); >> String maxLimit = application.getInitParameter("maxLimit"); >> >> try >> { >> ds = new OracleConnectionCacheImpl(); >> ds.setURL(jdbcURL); >> ds.setUser(user); >> ds.setPassword(password); >> ds.setMinLimit(Integer.parseInt(minLimit)); >> ds.setMaxLimit(Integer.parseInt(maxLimit)); >> } >> catch (Exception e) >> { >> application.log("Failed to create data source: " + e.getMessage()); >> } >> >> /* >> Initialize the database connection pool. >> */ >> try >> { >> ctx = new InitialContext(); >> ctx.lookup("java:comp/env/jdbc/ApplicationNameHere"); >> } >> catch (Exception e) >> { >> application.log("Failed to create database connection pool: " + >>e.getMessage()); >> } >> >> application.setAttribute("appDataSource", ds); >> } >> >> public void contextDestroyed(ServletContextEvent sce) >> { >> ServletContext application = sce.getServletContext(); >> application.removeAttribute("appDataSource"); >> // Close the connections in the DataSource >> try >> { >> ds.close(); >> } >> catch (java.sql.SQLException e) >> {} >> >> ds = null; >> } >> } >> >>-----Original Message----- >>From: Tim Funk [mailto:funkman@joedog.org] >>Sent: Friday, July 02, 2004 8:36 AM >>To: Tomcat Users List >>Subject: Re: How to use oracle pool instead of using DBCP pool? >> >> >>Nope. (Oracle's technical support /bulletin boards might be of more help) >> >>-Tim >> >>Claudio Carvalho wrote: >> >> >>>Hi Tim, >>> >>>I'm looking for an alternative directly on the application server, >> >>something >> >>>like putting an "oracle-pool" jar into tomcat/common/lib directory, have >> >>you >> >>>heard anything like that? >>> >>>Claudio Carvalho. >>> >>>----- Original Message ----- >>>From: "Tim Funk" >>>To: "Tomcat Users List" >>>Sent: Friday, July 02, 2004 10:52 AM >>>Subject: Re: How to use oracle pool instead of using DBCP pool? >>> >>> >>> >>> >>>>An alternative is to look at the DBCP java-docs. Cast your Connection to > > a > >>>>DBCP's ppoled connection class (or approrpiate). That class has a method >>>>called getDelegate() which returns the real connection from Oracle. Then >>> >>>cast >>> >>> >>>>that to the appropriate Oracle class. >>>> >>>>-Tim >>>> >>>>Claudio Carvalho wrote: >>>> >>>> >>>> >>>>>Cl�udio CarvalhoHi, >>>>> >>>>>I'm trying to get the CLOB working in my application and I'm having >>> >>>problems >>> >>> >>>>>with the Connection, so, does anybody knows how to use in Tomcat 5 the >>>>>oracle pool instead of using the DBCP pool? >>>>> >>>> >>--------------------------------------------------------------------- >>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org >>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org >> >> >> >> >>--------------------------------------------------------------------- >>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org >>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org >> >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org > > --------------------------------------------------------------------- > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org > > -- Emerson Cargnin Analista de Sistemas - Gerente Regional - Tubar�o Setor de Desenvolvimento de Sistemas - TRE-SC tel : (048) - 251-3700 - Ramal 3181 --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org