Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
18.8 Connection Pooling: A Case Study
513
Listing 18.22 ConnectionPoolServlet2.java
package coreservlets;
/** A variation of ConnectionPoolServlet that uses only
* a single connection, queueing up all requests to it.
* Used to compare timing results.
*/
public class ConnectionPoolServlet2
extends ConnectionPoolServlet {
protected int initialConnections() {
return(1);
}
protected int maxConnections() {
return(1);
}
}
Listing 18.23 ConnectionPoolServlet3.java
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
/** A variation of ConnectionPoolServlet that does NOT
* use connection pooling. Used to compare timing
* benefits of connection pooling.
*/
public class ConnectionPoolServlet3 extends HttpServlet {
private String url, username, password;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String table;
String query =
"SELECT firstname, lastname " +
" FROM employees WHERE salary > 70000";
try {
Connection connection =
DriverManager.getConnection(url, username, password);
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved