535
社区成员
发帖
与我相关
我的任务
分享
public class getCon implements ServletContextListener{
Session session=null;
Configuration option;
String username;
String password ;
String host;
public void contextDestroyed(ServletContextEvent arg0) {
try {
session.recycle();
} catch (Exception e) {
e.printStackTrace();
}
}
public void contextInitialized(ServletContextEvent arg0) {
try {
option= new PropertiesConfiguration("option.properties");
username=option.getString("username");
password=option.getString("password");
host=option.getString("host");
session = NotesFactory.createSession(host,username,password);
if(session!=null){
System.out.println("connect oa success");
}
else{
System.out.println("connect oa faild");
}
arg0.getServletContext().setAttribute("session", session);
arg0.getServletContext().setAttribute("option", option);
}catch (Exception e) {
e.printStackTrace();
}
}
}
这个类是连接数据库的