📄 connectionservlet.java
字号:
/* * @(#)ConnectionServlet * * Copyright (c) 1998 Karl Moss. All Rights Reserved. * * You may study, use, modify, and distribute this software for any * purpose provided that this copyright notice appears in all copies. * * This software is provided WITHOUT WARRANTY either expressed or * implied. * * @author Karl Moss * @version 1.0 * @date 04Apr98 * */package javaservlets.db;import javax.servlet.*;import javax.servlet.http.*;/** * <p>This is a simple servlet that holds a global connection * pool. */public class ConnectionServlet extends HttpServlet{ // Our connection pool. javaservlets.jdbc.ConnectionPool m_connectionPool; /** * <p>Get a JDBC connection from the pool * * @return JDBC connection */ public java.sql.Connection getConnection() throws Exception { java.sql.Connection con = null; if (m_connectionPool != null) { con = m_connectionPool.getConnection(); } return con; } /** * <p>Closes the given JDBC connection * * @param con JDBC Connection */ public void close(java.sql.Connection con) { if (m_connectionPool != null) { m_connectionPool.close(con); } } /** * <p>Initialize the servlet. This is called once when the * servlet is loaded. It is guaranteed to complete before any * requests are made to the servlet * * @param cfg Servlet configuration information */ public void init(ServletConfig cfg) throws ServletException { super.init(cfg); // Create our connection pool m_connectionPool = new javaservlets.jdbc.ConnectionPool(); // Initialize the connection pool. This will start all // of the connections as specified in the connection // pool configuration file try { m_connectionPool.initialize(); //("javaservlets.db.FastEmployeeList.cfg"); } catch (Exception ex) { // Convert the exception ex.printStackTrace(); throw new ServletException ("Unable to initialize connection pool"); } } /** * <p>Destroy the servlet. This is called once when the servlet * is unloaded. */ public void destroy() { // Tear down our connection pool if it was created if (m_connectionPool != null) { m_connectionPool.destroy(); } super.destroy(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -