mysql 连接池

来源:互联网 发布:nxpowerlite mac 破解 编辑:程序博客网 时间:2024/05/20 23:39

在Tomcat ---->conf----->context.xml 文件中的<Context></Context>中

 

写上 <WatchedResource>WEB-INF/web.xml</WatchedResource>
 <Resource name="jdbc/mysql"  auth="Container"  type="javax.sql.DataSource"  maxActive="100" maxIdle="30"
 maxWait="10000"  username="root"  password="root"  driverClassName="com.mysql.jdbc.Driver"
 url="jdbc:mysql://localhost/information?autoReconnect=true"  />

 

 

则在相应的测试文件中  写上: 

 

 try {
    Context context= new InitialContext();                                          //在Tomcat 中配置连接池
    DataSource  ds= (DataSource) context.lookup("java:/comp/env/jdbc/mysql");
      conn=ds.getConnection();

原创粉丝点击