Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 82355 invoked from network); 4 Dec 2006 20:01:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Dec 2006 20:01:25 -0000 Received: (qmail 60405 invoked by uid 500); 4 Dec 2006 20:01:21 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 60387 invoked by uid 500); 4 Dec 2006 20:01:21 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 60376 invoked by uid 99); 4 Dec 2006 20:01:21 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Dec 2006 12:01:21 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [63.166.247.24] (HELO dfw1wu03.atmosenergy.com) (63.166.247.24) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Dec 2006 12:01:10 -0800 Received: from DFW1WN05.atmosenergy.com (dfw1wn05.atmosenergy.com [172.16.7.25]) by dfw1wu03.atmosenergy.com (8.13.1/8.13.1) with SMTP id kB4K0fRw003057 for ; Mon, 4 Dec 2006 14:00:41 -0600 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Subject: RE: jsp optimization for db driver load and connection Date: Mon, 4 Dec 2006 14:00:41 -0600 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: jsp optimization for db driver load and connection Thread-Index: AccX1w0Er1Sl4gnrT7mJGv+hA/LkRAAA+j0Q From: "Miller, Steve" To: "Tomcat Users List" X-AtmosEnergy-Mail-1-MailScanner-Information: Please contact the HelpDesk for more information X-AtmosEnergy-Mail-1-MailScanner: Found to be clean X-AtmosEnergy-Mail-1-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (not cached, score=-4.399, required 3, autolearn=not spam, ALL_TRUSTED -1.80, BAYES_00 -2.60) X-AtmosEnergy-Mail-1-MailScanner-From: steve.miller@atmosenergy.com X-Virus-Checked: Checked by ClamAV on apache.org Ugh. Model 1 architecture :-) Connection pooling is the way to go here, definitely. Setup Tomcat to do it for you automatically on startup. Then, just grab a connection from the pool when you need it. Some good documentation on setting up and configuring Tomcat to do that is at http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.h tml In you JSP then, all you would have to write is (after importing java.sql.* and javax.naming.*): Context initContext =3D new InitialContext(); Context envContext =3D (Context)initContext.lookup("java:/comp/env"); DataSource ds =3D (DataSource)envContext.lookup("jdbc/foo"); = Connection conn =3D ds.getConnection(); Statement stmt =3D conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs =3D stmt.executeQuery(query1); //....run iterator loop and display stuff ResultSet rs =3D stmt.executeQuery(query2); //....run iterator loop and display stuff ..... ..... rs.close(); conn.close(); //returns connection to tomcat-managed pool...always a good practice to insert this!! The advantage to this of course is that several database connections are established when tomcat is started and then placed into a pool. All you do is grab one that exists....saving a *considerable* amount of transaction time and thus speeding up your page loads. In addition, should the database parameters change such as URL, username, or password, then you only have to change it in one place..the server.xml file. This is also important if you move between dev/test/prod environments and have to point at different database instances.=20 I don't know how many jsp pages you'll have to alter, but I would suggest looking at using a bean that does all of the stuff I wrote out above and returns an iterator or result set through a method. Then, do the bean stuff in the jsp code (sorry...running out of time here...lol). Again, I don't see any other way to improve performance within the scope/limitations you have defined.=20 Steve Miller "Grabbing A Tomcat By The Tail" --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org