81,122
社区成员




<Context>
<Resource name="jdbc/sql2005"
type="javax.sql.DataSource"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://localhost:1433;DatabaseName=OnlineStudy"
username="sa"
password="123456"
maxActive="10"
maxIdle="10"
minIdle="1"
maxWait="5000"
/>
</Context>
//JDNI API常用类
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.sql.DataSource;
public class TestListener implements ServletContextListener {
public void contextDestroyed(ServletContextEvent sce) {
}
public void contextInitialized(ServletContextEvent sce) {
try {
InitialContext context= new InitialContext();
//sql2005
DataSource ds=(DataSource) context.lookup("java:/comp/env/jdbc/sql2005");
DBConnection.registDataSource(ds);
System.out.println("连接池已经启动!");
} catch (NamingException e) {
e.printStackTrace();
}
}