提交 976bc8b3 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 1e0db2e8
package org.h2.tools.servlet;
import javax.servlet.*;
import java.sql.*;
public class DbStarter implements ServletContextListener {
private Connection conn;
public void contextInitialized(ServletContextEvent servletContextEvent) {
try {
Class.forName("org.h2.Driver");
// You can also get the setting from a context-param in web.xml:
ServletContext servletContext = servletContextEvent.getServletContext();
// String url = servletContext.getInitParameter("db.url");
conn = DriverManager.getConnection("jdbc:h2:test", "sa", "");
servletContext.setAttribute("connection", conn);
} catch (Exception e) {
e.printStackTrace();
}
}
public Connection getConnection() {
return conn;
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论