myconnectionmanager.java

来自「java servlet编程源码」· Java 代码 · 共 18 行

JAVA
18
字号
import javax.servlet.*;
import javax.servlet.http.*;

public class MyConnectionManager implements ServletContextListener {

  public void contextInitialized(ServletContextEvent e) {
    Connection con =     // create connection
      e.getServletContext().setAttribute("con", con);
  }

  public void contextDestroyed(ServletContextEvent e) {
    Connection con =
       (Connection) e.getServletContext().getAttribute("con");
    try { con.close(); } 
    catch (SQLException ignored) { } // close connection
  }
}

⌨️ 快捷键说明

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