tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Miller, Steve" <>
Subject RE: jsp optimization for db driver load and connection
Date Mon, 04 Dec 2006 20:00:41 GMT
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

In you JSP then, all you would have to write is (after importing
java.sql.* and javax.naming.*):

            Context initContext = new InitialContext();
            Context envContext =
            DataSource ds = (DataSource)envContext.lookup("jdbc/foo"); 
		Connection conn = ds.getConnection();
		Statement stmt =
		ResultSet rs = stmt.executeQuery(query1);
		// iterator loop and display stuff
		ResultSet rs = stmt.executeQuery(query2);
		// iterator loop and display stuff

		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

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:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message