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 = new InitialContext();
            Context envContext =
(Context)initContext.lookup("java:/comp/env");
            DataSource ds = (DataSource)envContext.lookup("jdbc/foo"); 
                Connection conn = ds.getConnection();
                Statement stmt =
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
                ResultSet rs = stmt.executeQuery(query1);
                //....run iterator loop and display stuff
                ResultSet rs = 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. 

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. 

Steve Miller
"Grabbing A Tomcat By The Tail"

---------------------------------------------------------------------
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