⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionpoolservlet.java

📁 使用jsp+my sql构成的电子管理系统。能实现借书
💻 JAVA
字号:
package sjservlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

/** A class that extent the Connection Pool servlet which 
 *  JDBC connections for this applicaiton (Java Library)
 *
 *  © 2002 Song Jing; may be freely used or adapted.
 */
 
public class ConnectionPoolServlet extends HttpServlet {
  	protected ConnectionPool connectionPool;
  
  	public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
  			throws ServletException, IOException {
  	}

  /** Initialize the connection pool when servlet is
   *  initialized. To avoid a delay on first access, load
   *  the servlet ahead of time yourself or have the
   *  server automatically load it after reboot.
   */
  
	public void init() {
		int vendor = DriverUtilities.MYSQL;
    	String driver = DriverUtilities.getDriver(vendor);
    	String host = "localhost";
    	String dbName = "jsp_library";
    	String url = DriverUtilities.makeURL(host, dbName, vendor);
    	String username = "root";
    	String password = "masteryoda";
    	try {
      		connectionPool =
        	new ConnectionPool(driver, url, username, password,
                           initialConnections(),
                           maxConnections(),
                           true);
    	} catch(SQLException sqle) {
      		System.err.println("Error making pool: " + sqle);
      		getServletContext().log("Error making pool: " + sqle);
      		connectionPool = null;
    	}
  	}

  	public void destroy() {
    	connectionPool.closeAllConnections();
  	}

  	/** Override this in subclass to change number of initial
   	*  connections.
   	*/
  
  	protected int initialConnections() {
    	return(3);
  	}

  	/** Override this in subclass to change maximum number of 
   	*  connections.
   	*/

    protected int maxConnections() {
    	return(60);
  	}
  
  	public void doPost(HttpServletRequest request,
					   HttpServletResponse response)
		   throws ServletException, IOException{
		doGet(request, response);
	}
	
	protected void gotoPage(String address, 
						  HttpServletRequest request,
						  HttpServletResponse response)
			throws ServletException, IOException {
		RequestDispatcher dispatcher = 
			getServletContext().getRequestDispatcher(address);
		dispatcher.forward(request, response);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -